Vue强制刷新视图数据

在我们使用Vue进行开发的过程中,可能会遇到一种情况:当生成Vue实例后,当再次给数据赋值时,有时候并不会自动更新到视图上去。

此时需要强制刷新视图数据。

解决方法:使用Vue.set方法。

target:要更改的数据源(可以是对象或者数组),

key:要更改的具体数据,

value :重新赋的值。

例如:

Vue.set(
    that.tableData.list[i],
    "shippingYard",
    that.itemvalue
);

若出现Vue is undefined的报错,则需要导入Vue。

import Vue from 'vue'

或是使用this.$set()强制刷新视图数据,如

//this.currentData.bound = this.value
this.$set(this.currentData,'bound',this.value)