当前位置:网站首页>Improvement of wechat applet 28 hot search list ①
Improvement of wechat applet 28 hot search list ①
2022-07-25 19:13:00 【Mu Quanyu [dark cat]】
28.1 Hot search list 、placeholder Dynamic data
Interface http://localhost:3000/search/default

onLoad(options) {
this.getInitData();
},
// Get initialized data
async getInitData() {
let placeholderData = await request("search/default",{
});
this.setData({
placeholderContent: placeholderData.data.showKeyword
});
},
<input type="text" placeholder="{
{placeholderContent}}" placeholder-class="placeholder"></input>

Interface http://localhost:3000/search/hot/detail

onLoad(options) {
this.getInitData();
},
// Get initialized data
async getInitData() {
let placeholderData = await request("search/default",{
});
let hotListData = await request("search/hot/detail");
this.setData({
placeholderContent: placeholderData.data.showKeyword,
hotList: hotListData.data
});
},
<view class="searchContainer">
<!-- Head -->
<view class="header">
<view class="searchInput">
<text class="iconfont icon-search searchIcon"></text>
<input type="text" placeholder="{
{placeholderContent}}" placeholder-class="placeholder"></input>
</view>
<text class="cancel"> Cancel </text>
</view>
<!-- Hot search list -->
<view class="hotContainer">
<view class="title"> Hot search list </view>
<!-- Hot search list -->
<view class="hotList">
<view class="hotItem" wx:for="{
{hotList}}" wx:key="score">
<text class="order">{
{index + 1}}</text>
<text>{
{item.searchWord}}</text>
<image class="iconImg" wx:if="{
{item.iconUrl}}" src="{
{item.iconUrl}}"></image>
</view>
</view>
</view>
</view>

28.2 Fuzzy matching search data
bindinput event : Whether or not you lose focus , Just change the content , All trigger .
bindcheck event : You need to lose focus to trigger this event .
Interface http://localhost:3000/search?keywords=fade&limit=10

<input bindinput="handelInputChange" type="text" input placeholder="{
{placeholderContent}}" placeholder-class="placeholder"></input>
data: {
placeholderContent: '', // placeholder Content
hotList: [], // Hot search list data
searchContent: '', // Form item data entered by the user
searchList: [], // Keyword fuzzy matching data
},
// obtain Function of searching data
async getSearchList(){
let searchListData = await request("search", {
keywords: this.data.searchContent, limit: 10});
this.setData({
searchList: searchListData.result.songs
})
},
// The event that the content of the form changes
handelInputChange(event) {
console.log(event);
this.setData({
searchContent: event.detail.value.trim()
});
// Function throttling
if (isSend) {
return;
}
isSend = true;
setTimeout(() => {
isSend = false;
this.getSearchList();
}, 1000);
},

28.3 Search content display
Write it html General structure
<view class="searchContainer">
<!-- Head -->
<view class="header">
<view class="searchInput">
<text class="iconfont icon-search searchIcon"></text>
<input bindinput="handelInputChange" type="text" input placeholder="{
{placeholderContent}}" placeholder-class="placeholder"></input>
</view>
<text class="cancel"> Cancel </text>
</view>
<block wx:if="{
{searchList.length}}">
<!-- Search content display -->
<view class="showSearchContent">
<view class="searchContent"> Search content :{
{searchContent}}</view>
<view class="searchList">
<view class="searchItem" wx:for="{
{searchList}}" wx:key="id">
<text class="iconfont icon-search"></text>
<text>{
{item.name}}</text>
</view>
</view>
</view>
</block>
<block wx:else>
<!-- Hot search list -->
<view class="hotContainer">
<view class="title"> Hot search list </view>
<!-- Hot search list -->
<view class="hotList">
<view class="hotItem" wx:for="{
{hotList}}" wx:key="score">
<text class="order">{
{index + 1}}</text>
<text>{
{item.searchWord}}</text>
<image class="iconImg" wx:if="{
{item.iconUrl}}" src="{
{item.iconUrl}}"></image>
</view>
</view>
</view>
</block>
</view>
/* pages/search/search.wxss */
.searchContainer {
padding: 0 20rpx;
}
.header {
display: flex;
height: 60rpx;
line-height: 60rpx;
padding: 10rpx 0;
}
.searchInput {
position: relative;
flex: 1;
background: rgba(237,237,237,0.3);
border-right: 30rpx;
}
.cancel {
width: 100rpx;
text-align: center;
}
.searchIcon {
position: absolute;
left: 15rpx;
}
.searchInput input{
margin-left: 50rpx;
height: 60rpx;
}
/*h5 One of the new features , Can be placeholder Set up class and style */
.placeholder {
color: #d43c33;
font-size: 28rpx;
}
/* Hot search list */
.hotContainer .title {
font-size: 28rpx;
height: 80rpx;
line-height: 80rpx;
border-bottom: 1rpx solid #eee;
}
.hotList {
display: flex;
flex-wrap: wrap;
}
.hotItem {
width: 50%;
height: 80rpx;
line-height: 80rpx;
font-size: 26rpx;
}
.hotItem .order {
margin: 0 10rpx;
}
.hotItem .iconImg {
width: 35rpx;
height: 20rpx;
margin-left: 10rpx;
}
/* Search content display */
.searchContent {
color: rgba(107, 100, 238, 0.96);
height: 80rpx;
line-height: 82rpx;
font-size: 24rpx;
border-bottom: 1rpx solid #d43c33;
}
.searchItem {
height: 80rpx;
line-height: 80rpx;
display: flex;
}
.searchItem .content {
flex: 1;
margin-left: 20rpx;
border-bottom: 1rpx solid #eee;
font-size: 26rpx;
}
// pages/search/search.js
import request from "../../utils/request";
let isSend = false; // be used for function Throttling use
Page({
/** * Initial data of the page */
data: {
placeholderContent: '', // placeholder Content
hotList: [], // Hot search list data
searchContent: '', // Form item data entered by the user
searchList: [], // Keyword fuzzy matching data
},
/** * Life cycle function -- Monitor page loading */
onLoad(options) {
this.getInitData();
},
// Get initialized data
async getInitData() {
let placeholderData = await request("search/default",{
});
let hotListData = await request("search/hot/detail");
this.setData({
placeholderContent: placeholderData.data.showKeyword,
hotList: hotListData.data
});
},
// obtain Function of searching data
async getSearchList(){
if(!this.data.searchContent){
this.setData({
searchList: []
});
return;
}
let searchListData = await request("search", {
keywords: this.data.searchContent, limit: 10});
this.setData({
searchList: searchListData.result.songs
})
},
// The event that the content of the form changes
handelInputChange(event) {
console.log(event);
this.setData({
searchContent: event.detail.value.trim()
});
// Function throttling
if (isSend) {
return;
}
isSend = true;
setTimeout(() => {
isSend = false;
this.getSearchList();
}, 500);
},
/** * Life cycle function -- Listening page first rendering completed */
onReady() {
},
/** * Life cycle function -- Monitor page display */
onShow() {
},
/** * Life cycle function -- Monitor page hidden */
onHide() {
},
/** * Life cycle function -- Monitor page uninstall */
onUnload() {
},
/** * Page related event handler -- Monitor user pull-down action */
onPullDownRefresh() {
},
/** * Handling function of page pull bottom event */
onReachBottom() {
},
/** * Users click the upper right corner to share */
onShareAppMessage() {
}
})


边栏推荐
- How many lines of code is appropriate for a function? Clean Code
- ThreadLocal Kills 11 consecutive questions
- Hough transform understanding [easy to understand]
- Basic mode of music theory
- 7/24 training log
- MySQL sub query (selected 20 sub query exercises)
- 【加密周报】加密市场有所回温?寒冬仍未解冻!盘点上周加密市场发生的重大事件!
- Juzhi cloud computing opens a new era to the "proprietary cloud" of Youfu network
- SQL Server 2019 安装教程
- [applet development] do you know about applet development?
猜你喜欢

常用的开发软件下载地址

QIIME2得到PICRUSt2结果后如何分析
![[encryption weekly] has the encryption market recovered? The cold winter has not thawed yet! Check the major events in the encryption market last week!](/img/6d/b037208996ce52016d014062deaa1f.jpg)
[encryption weekly] has the encryption market recovered? The cold winter has not thawed yet! Check the major events in the encryption market last week!

Alibaba cloud technology expert haochendong: cloud observability - problem discovery and positioning practice

小程序毕设作品之微信校园维修报修小程序毕业设计成品(3)后台功能

Clip can also do segmentation tasks? The University of Gottingen proposed a model clipseg that uses text and image prompt and can do three segmentation tasks at the same time, squeezing out the clip a

聊聊sql优化的15个小技巧

InTouch advanced alarm (alarm filtering)

Analysis of the internet jam in IM development? Network disconnection?

Actual combat of MySQL database design project of online mall system
随机推荐
Youfu network was invited to attend the 2022 national CIO conference and won the title of "CIO trusted brand"
Pymoo learning (8):grades
srec_cat 常用参数的使用
Care for front-line epidemic prevention workers, Haocheng JIAYE and Gaomidian sub district office jointly build the great wall of public welfare
华为交换机系统软件升级和安全漏洞修复教程
qt exec和show的区别
[applet development] detailed explanation of host environment
Hongmeng - Damiao computing Sketchpad - Introduction
SQL realizes 10 common functions of Excel, with original interview questions attached
Fearless of high temperature and rainstorm, how can Youfu network protect you from worry?
Yarn installation and use tutorial [easy to understand]
Common development software download addresses
Actual combat of MySQL database design project of online mall system
telnet安装以及telnet(密码正确)无法登录!
Pymoo学习 (8):Gradients
[919. Complete binary tree inserter]
基于Mysql-Exporter监控Mysql
ThreadLocal Kills 11 consecutive questions
[web technology] 1391 page visualization building tool, previous life and present life
小程序毕设作品之微信校园维修报修小程序毕业设计成品(5)任务书