watch异步操作


异步操作:

1.ajax,

2.定时器

3.点击事件

4.数据库操作

特点:代码不等待,后续代码会继续执行。

  watch:{
    //watch作用监测已经存在的数据 newVal 新值,oldVal 旧值
    searchName(newVal,oldVal){
   axios.get("http://localhost:3001/brands?name_like="+newVal).then((res) => {
        const { status, data } = res;
        if (status === 200) {
          this.list = data;
        }
      });
    }
  },

  ======================全部代码-如果不是异步操作数据库也可以通过集合中的filter进行过滤搜索=====================================






vue