vue watch监听触发节流
export default {
  name: 'HelloWorld',
  props: {
    msg: String
  },
  data () {
    return {
      search: {
        input: '',
        timer:null
      }
    }
  },
  watch: {
    'search.input': {
      handler (value) {
        if (this.timer) {
          clearTimeout(this.timer)
        }
        this.timer = setTimeout(() => {
          this.getList();
        }, 1000)
 
      },
      deep: true
    }
  },
  methods: {
    getList(){
      //在这里你可以请求你的接口,拿到你想要的数据
      console.log(1)
    }
  }
}
</script>


 我是马丁的车夫,欢迎转发收藏!

posted on 2020-12-26 17:54  马丁的车夫  阅读(644)  评论(0编辑  收藏  举报