渲染:
搜索分类有两种情况。通常,当用户完成输入时,他点击确定按钮,将请求向后发送。还有一个就是我在输入的时候把请求发送到后台,但是会有一个性能问题,就是页面会因为一直发送请求而卡住。这里,使用截取功能。当用户点击键盘超过300毫秒时,请求将被发送,否则不会被请求。
search.vue
模板div id=' search '输入类型=' text' class=' search '占位符=' search ' v-model . trim=' title '/div/template js:
Script//throttle函数const delay=(function(){ let timer=0;返回函数(回调,ms) { clearTimeout(定时器);timer=setTimeout(回调,毫秒);};})();导出默认{ name: 'search ',data() { return { title: ' ',search :[]};},watch : {//watch title change title(){ delay(()={ this . fetchdata();}, 300);},},方法: { async fetch data(val){ const RES=wait this。fetch ({URL : '写你的URL ',方法:' get ',params : { title : this . title },});this . search=RES . data . list;},},mounted() {},};/script以上vue边输入边搜索功能的例子,都是边肖分享给大家的内容,希望能给大家一个参考和支持。