vue数据结构有多层,改变二级结构数据,dom节点没有重新渲染的坑

$nextTick这个方法的意思大概就是数据更新后触发dom节点更新吧,数据多层的时候vue监听不到底层的数据变化,可以使用watch方法深度监听数据的变化,然后使用$nextTick在数据变化后触发dom节点更新,并且数据获取到后要遍历数据放进定义的数组里不然也不会出发dom节点更新

$.each(data.resultData,function (index,item) {
              item.showChild = false;
              self.tableData.push(item)
            })
showDetail(item){
            console.log(this.tableData)
            console.log(item)
            this.$nextTick(function () {
              item.showChild = !item.showChild
            })
          },
watch:{
          tableData:{
            handler:function(val,oldVal){
              this.tableData = val;
            },
            // 深度观察
            deep:true
          }
        },

 

posted @ 2018-04-18 18:40  蓝海域的春天  阅读(4651)  评论(0编辑  收藏  举报