1.
首先导入lodash的debounce函数
import { debounce } from 'ladash';
2.
<el-input v-model="form.assetCoding" placeholder="请选择资产" @input="aaa">
@input当输入框中的数据发生改变时触发
3.
data() {
return {
form: {
assrtCoding: DF202302111112,
}
}
},
created() {
this.debounced = debounce(this.search,500)
},
methods: {
reset(assetCoding) {
this.from = {
...
assetCoding: assetCoding
}
},
aaa() {
this.debounced(this.form.assetCoding)
},
search(keyword) {
if(keyword.length == 14) {
list({assetCoding: keyword}).then((res)=> {
if(res.rows.length == 1) {
this.form = res.rows[0]
}else {
this.reset(this.form.assetCoding)
}
})
}
}
},
beforeDestory() {
this.debounced.cancel()
}