I would like to know why i am getting the following error:
error 'msg_' is assigned a value but never used
despite that the variable msg_
is used in the following context as shown in the below posted code:
<HelloWorld :msg="msg_"/>
App.vue:
<template>
<img alt="Vue logo" src="./assets/logo.png">
<HelloWorld :msg="msg_"/>
</template>
<script>
import HelloWorld from './components/HelloWorld.vue'
import { ref } from 'vue'
export default {
name: 'App',
components: {
HelloWorld
},
setup(props) {
var msg_ = ref({msg:"msg from parent"})
return {
props
}
}
}
</script>
>Solution :
You have to return msg_ from the setup() function.
setup(props) {
var msg_ = ref({msg:"msg from parent"})
return {
props,
msg_,
}
}
Also it better to use const and let instead of var.