解决问题:子组件的值更改了,兄弟组件的值没有改变,(一个组件中同时包含两个子组件,子组件之间应该如何传值,针对数据为对象数组的不能直接改变渲染)

1.定义一个New.js中间文件

2.在组件1中,引入其

New.$emit('getSome', {change: true, item: item})    第一个参数是事件名,第二个为传递的对象
3.在组件2中,引入其
created(){
    New.$on('getSome', data => {
      if(data.change===true){
        this.$set(this.duplicates, 'analysis', data.item.analysis)
        this.$set(this.duplicates, 'answers', JSON.parse(JSON.stringify(data.item.answers)))
        this.$set(this.duplicates, 'content', data.item.content)
        this.$set(this.duplicates, 'difficulty', data.item.difficulty)
        this.$set(this.duplicates, 'options', JSON.parse(JSON.stringify(data.item.options)))
        this.$set(this.duplicates, 'source', data.item.source)
        this.$set(this.duplicates, 'sources', JSON.parse(JSON.stringify(data.item.sources)))
      }
    })
 
posted @ 2021-03-15 16:20  yaqian96  阅读(228)  评论(0)    收藏  举报