美文网首页
vue 数据监听

vue 数据监听

作者: 若水亦城空 | 来源:发表于2019-10-29 17:17 被阅读0次

    选项:deep(监听单个值)

    为了发现对象内部值的变化,可以在选项参数中指定 deep: true 。注意监听数组的变动不需要这么做。

    选项:immediate (监听数组内部某个值)

    在选项参数中指定 immediate: true 将立即以表达式的当前值触发回调:

     data() {
        return {
          changevalue: this.listValue,
          changetitle: this.listTitle,
          changeYear: this.dataYear,
        };
      },
      props: {
        listValue: {
          type: String,
          default: ""
        },
        listTitle: {
          type: String,
          default: ""
        },
        dataYear: {
          default: ""
        },
      },
      components: {
      },
      watch: {
        listValue: {
          handler(newVal) {
            this.changevalue = newVal;
            setTimeout(() => {
              this.initStyle(this.typeYearbooks, this.listValue);
            }, 100);
          },
          deep: true,
          immediate: true
        },
        listTitle: {
          handler(newTitle) {
            this.changetitle = newTitle;
            setTimeout(() => {
              this.initStyle(this.typeYearbooks, this.listValue);
            }, 100);
          },
          deep: true,
          immediate: true
        },
        dataYear: {
          handler(newValue) {
            this.changeYear = newValue;
            setTimeout(() => {
            this.initStyle(this.typeYearbooks, this.listValue);
            // console.log(this.$refs.fromDomNoke);
            }, 100);
          },
          deep: true,
          immediate: true
        },
        dialogChartVisible(value) {
          if (!value) {
            this.dialogChange = value;
            this.testChartsList = {};
          }
        }
      },

    相关文章

      网友评论

          本文标题:vue 数据监听

          本文链接:https://www.haomeiwen.com/subject/iyugvctx.html