[vue.js]解决子组件无法获取父组件store中的值的问题

来源:互联网 发布:巨人网络为什么倒闭 编辑:程序博客网 时间:2024/05/18 02:41

子组件:

props:['myDetail']

父组件:

<子组件 :myDetail="detail"></子组件>computed:{    detail(){        return this.$store.state.XXXX.yyyy    }}

子组件的参数值不会随着父组件store中参数值的改变而改变

修改为
父组件:

data:{detail:{}}methods:{    reloadDetail(){        this.detail=JSON.parse(JSON.stringify(this.$store.state.XXXX.yyyy));    }}

调用reloadDetail方法,以及必须加上JSON.parse(JSON.stringify())方法,子组件的值才会随着父组件参数值的变化而变化

0 0
原创粉丝点击