<script>
 computed: {
    search() {
      return this.myUaData.searchSite;
    }
  },
  watch: {
    search(newValue, oldValue) {
      if (newValue === "") {
        //如果为空,执行方法获取list
        this.getList();
      }
    }
  }
</script>
<template>
          <el-input
            placeholder="请输入关键字搜索"
            icon="search"
            v-model.trim="myUaData.searchSite"
            size="medium"
            class="search-input"
            @keyup.native.enter="getList()"
            clearable
          ></el-input>
</template>

 

补充:若监听的数组对象 ,则用

    search: {
      handler: function(newVal, oldVal) {},
      deep: true
    }

另外存在一种情况:watch初次触发的时需要初始化,可能导致监听不生效,通过immediate来控制 ,true则立即执行,false则初始化不执行

    search: {
      immediate: true,
      handler: function(newVal, oldVal) {
      }
    },

 

Logo

前往低代码交流专区

更多推荐