各位大佬,我是新手,在学习vue组件时,子组件想通过props属性获取到父组件的值,却怎么都不能生效,大佬们能不能给指出总是所在,不胜感激!vue版本为2.9.6。
子组件代码
<template>
<div>{{msg}}</div>
</template>
<script>
export default {
props: ['msg']
}
</script>
<style scoped>
</style>
父组件代码
<template>
<div class="hello">
<Demo></Demo>
</div>
</template>
<script>
import Demo from './Demo.vue'
export default {
name: 'HelloWorld',
data () {
return {
msg: 'Welcome to Your Vue.js App'
}
},
components: {
Demo
}
}
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
</style>