vue中 this.$set的用法

//此时对象的值更改了,但是视图没有更新

this.tableData.forEach((item) => {
       //回显数据
  if (!item.hisLocationCode) {
    item.hisLocationCode =
    item.hisLocationName && item.hisLocationName != "-" ? item.hisLocationName : " ";
  }
});

//$set可以触发更新视图

  this.tableData.forEach((item) => {
                    //回显数据
                    if (!item.hisLocationCode) {
                      this.$set(
                        item,
                        "hisLocationCode",
                        item.hisLocationName && item.hisLocationName != "-"
                          ? item.hisLocationName
                          : ""
                      );
                    }
                  });
posted @ 2021-10-21 17:04  xiao-jie-tian  阅读(262)  评论(0)    收藏  举报