Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

unable to set value to a bound property

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading