在父组件Member.vue中,我通过吸气剂从Vuex存储中获取用户和帐户数据
<script>
import { mapGetters } from 'vuex'
import Profile from '@/components/Member/Profile.vue'
export default {
name: 'member',
components: {
Profile
},
data () {
return {
}
},
computed: {
...mapGetters(['user', 'account'])
},
methods: {
},
created () {
console.log('MEMBER VUE CREATED user: ', this.user)
console.log('MEMBER VUE CREATED account: ', this.account)
}
}
</script>
在子组件配置文件中,我从props获取用户数据,但是它是未定义的...
<script>
export default {
name: 'profile',
props: ['user'],
computed: {
...
},
methods: {
...
},
created: function () {
console.log('user data from parent component:')
console.log('user: ', this.user)
}
}
</script>
我想这与亲子生命周期挂钩有关...但是我看不出如何轻松地解决它...谢谢您的反馈
答案 0 :(得分:1)
在您的HTML中,您需要将该属性传递给子级,在这种情况下,它类似于:
<profile :user="user" ...></profile>