uni-app搜索功能前后端开发(页面)
博客说明
文章所涉及的资料来自互联网整理和个人总结,意在于个人学习和经验汇总,如有什么地方侵权,请联系本人删除,谢谢!
借助的插件地址
插件地址
展示
前端是使用vue,后端使用Java的springBoot开发
监控搜索框
uni-app
注意根据自己的需求来改
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| async getSearch(keyword) { let [err, res] = await this.$http.post('/shop/search',{ name:keyword }); this.$http.errorCheck(err, res); this.keywordList = []; this.keywordList = this.drawCorrelativeKeyword(res.data.data, keyword); },
drawCorrelativeKeyword(keywords, keyword) { var len = keywords.length, keywordArr = []; for (var i = 0; i < len; i++) { var row = keywords[i]; var html = row.name.replace(keyword, "<span style='color: #9f9f9f;'>" + keyword + "</span>"); html = '<div>' + html + '</div>'; var tmpObj = { keyword: row.name, htmlStr: html, id:row.id }; keywordArr.push(tmpObj) } return keywordArr; },
|
后端接口开发
1 2 3 4 5 6 7 8 9 10 11 12
|
@ApiOperation(value = "搜索商家", notes = "首页搜索商家") @ApiImplicitParam(name="name", value="商家名字", required = true, dataType = "String") @RequestMapping(value = "/search", method = {RequestMethod.POST}) public Object search(@RequestParam(defaultValue = "") String name) { List<Shop> shops = shopService.list(new QueryWrapper<Shop>().select("id","name").eq("flag", 1).like("name",name)); return Result.success(shops); }
|
效果
根据自己的需求改一下vue绑定的值
热门搜索列表
uni-app
1 2 3 4 5 6 7 8 9
| async loadHotKeyword() { let [err, res] = await this.$http.get('/shop/searchList'); console.log(res); this.$http.errorCheck(err, res); this.hotKeywordList = res.data.data; },
|
后端
1 2 3 4 5 6 7 8 9 10
|
@ApiOperation(value = "搜索热门列表", notes = "搜索热门列表") @GetMapping("/searchList") public Object searchList() { List<ShopSearch> shopSearchs = shopSearchService.list(new QueryWrapper<ShopSearch>().orderByDesc("number")); return Result.success(shopSearchs); }
|
其他的功能是用了插件里面的
感谢
uni-app
以及勤劳的自己,个人博客,GitHub