搜索+防抖
1.以每时每刻这个项目为例,很多页面都有搜索功能,而且跳转的时同一个搜索页面,在完成搜索功能后,在返回原页面,需要一个唯一标识来记载
goSearch() {
this.$router.push({
path: "/search",
query: { name: this.$route.name }});
}
[ {
path: '/exam',
name: 'exam',
component: exam,
meta: {
title: '仿真模考'
}
},
{
path: '/paperPackage',
name: 'paperPackage',
component: paperPackage,
meta: {
title: '套卷练习'
}
},
]
2.在搜索页面接受
created() {
this.name = this.$route.query.name;
},
3.点击搜索按钮触发事件
let arr = ["exam","paperPackage"];
arr.forEach(value => {
if (value == this.name) {
this.$router.push({
name: value,
params: { keywords: this.keywords }
});
}
});
4.在数据页面接受关键字
created() {
this.keywords = this.$route.params.keywords;
},
5.然后在执行数据请求,携带关键字
mounted() {
},
6.防抖的简单实现
keyInput: _.debounce(function() {
this.getData();
}, 2000),