watch监听路由、数据变化

1、watch监听路由变化

watch: {
    $route (to, from) {
      if (from.fullPath === '/Organize/attendPer') {
        Object.assign(this.canteenDetailAdd[from.params.id].flowInstanceStepApproveAdd, this.attendPer)
        // 解决视图 不立即更新
        this.canteenDetailAdd.splice(this.canteenDetailAdd.length, 0)
      }
      // 可以通过 watch 路由监听,获取到id  可以解决根据循环生成的数据,携带id进行不同操作
      // console.log(to,from) // 可以看到from 或 to 是一个对象,对象包括:
      // {name: "Organize", meta: {…}, path: "/Organize/attendPer", hash: "", query: {…},?…}
      // params 的详细内容:params:{type: "attendPer", id: 0}
    }
  },

2、watch监听数据变化



 

你可能感兴趣的:(前端,vue)