组件内
<Button v-on:click="hello">测试节流</Button> <Input type="text" v-model="text" @input="showText"/>
script 部分
import _ from 'lodash'
methods: {
// 节流
hello: _.throttle(function() {
this.show2()
},5000),
show2() {
this.$Message.info("这里是v-my-on代替v-on实现");
},
// 防抖
showText: _.debounce(function() {
console.log(this.text);
},2000)
},
created() {
this.showText(); // 这里对防抖预执行一次,防止debounce函数第一次未执行
}
posted on
浙公网安备 33010602011771号