Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vue.js/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vue.js Vuejs通过引用更新v-for_Vue.js_Vuejs2 - Fatal编程技术网

Vue.js Vuejs通过引用更新v-for

Vue.js Vuejs通过引用更新v-for,vue.js,vuejs2,Vue.js,Vuejs2,所以我有一个简单的v-for,v-for中的每个项目都有一个@点击 <result-index> <li v-for="(result, index) in results" @click="getReult(results[index])"> {{ result.name }} </li> </result-index> 这会更新父结果(我们使用的@click-on),但不会更新该结果的v-for-refer

所以我有一个简单的v-for,v-for中的每个项目都有一个@点击

<result-index>
    <li v-for="(result, index) in results" @click="getReult(results[index])">
        {{ result.name }}
     </li>
 </result-index>

这会更新父结果(我们使用的@click-on),但不会更新该结果的v-for-reference,因此,当它发生变化时,我如何更新结果的v-for-reference,也请注意,由于此的css设计,我不可能将v-for放入v-for中,当
this.result=result
this.result
指向内存的一个地址时,它需要与
  • ..

    分开

    接收到输入事件,然后将新值分配给
    此.result
    ,它将使
    this.result=newValue
    (实际上指向newValue的另一个内存地址),因此它不会像您预期的那样更改
    结果[索引]
    的值

    检查以下演示:

    const test={result:[]}
    设value1=['a']
    console.log('org',test)
    test.result=value1//使用新数组赋值
    log('替换整个阵列',测试)
    value1[0]=“b”//将新值分配给value1的第一个元素
    
    console.log('Update one item of the array',test)//test.result和value1指向内存的同一地址,然后上帝保佑你。。。如果你想创建一个asnwer,我将标记为最佳。
    methods: {
        getResult: function(result) {
            // when the child <result-update> updates this, it updates fine, but it doesn't update the v-for reference of this.
            this.result = result;
        }
    }
    
    <result-index>
        <li v-for="(result, index) in results" @click="getReult(results[index])">
             {{ result.name }}
        </li>
        <result-update v-if="result" v-model="result">
         //... here is a form to access the result and update it
        </result-update>
    </result-index>
    
    methods: {
        update(e) {
            this.$emit("input", //data here...);
        },
    }
    
    watch: {
        value: function() {
            this.form = this.value;
        },
    },
    
    created() {
        this.form = __.cloneDeep(this.value);
    }