vue 数据监听

选项: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 = {};
      }
    }
  },
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。