微信小程序之搜索分頁(yè)功能的實(shí)現(xiàn)代碼
直接上代碼:
wxml:
<wxs src="../wxs/changeimg.wxs" module="changeimg" />
<view class="container">
<view class="search_input">
<image class="back" src="" mode="widthFix"></image>
<input type="text" class="weui-input" maxlength="10" placeholder="搜索" value="{{value}}" bindinput="changeModel" bindconfirm="search" data-key="value"/>
<image class="scan_code" src="" mode="widthFix" ></image>
</view>
<!--搜索菜品做法列表 -->
<view class="modus_operandi">
<view class="search_no" wx:if="{{searchLen==0&&clickEnter==1}}" >
<text>很抱歉,沒(méi)有找到您要搜索的資料/(ㄒoㄒ)/~~</text>
</view>
<view class="modus_operandi_total"
wx:for="{{searchData}}"
wx:key="id"
bindtap="jumpVegetables"
data-cid="{{item.classid}}"
>
<image class="modus_operandi_pic" mode="widthFix" src="{{changeimg.getimageurl(item.defaultpic)}}"></image>
<view class="modus_operandi_title">{{item.title}}</view>
</view>
</view>
</view>
wxss:
page{
background: #fff;
}
.back{
width: 20rpx;
height: 20rpx;
margin-top: 39rpx;
margin-right: 20rpx;
margin-left: 20rpx;
}
.search_input {
height: 110rpx;
padding: 10rpx;
background: url("https://mini.qianjiwang.cn/img/top.png")no-repeat center;
background-size: 100% 700rpx;
display: flex;
position: relative;
}
.search_input input {
height: 70rpx;
background-color: #fff;
border-radius: 50rpx;
font-size: 32rpx;
color: #000;
width: 80%;
margin-left: 0rpx;
background: #a7d9fe;
margin-top: 20rpx;
padding-left: 30rpx;
}
.scan_code{
flex: 1;
width: 40rpx;
height: 40rpx;
margin-left: 30rpx;
margin-top: 27rpx;
}
.modus_operandi{
padding: 20rpx;
display: flex;
flex-wrap: wrap;
margin-top: 50rpx;
}
.modus_operandi_total{
width: 47%;
padding: 10rpx;
}
.modus_operandi_pic{
height:215rpx!important;
border-radius: 10rpx;
}
.modus_operandi_title{
text-align: center;
}
js:
// pages/pro/index.js
import menuData from "../../bindData/rightMenuCtrl.js"
import proData from "../../bindData/searchFoodData.js"
Page({
/**
* 頁(yè)面的初始數(shù)據(jù)
*/
data: {
pageName: "",
ShowLonding: { londing: false, message: "", contNone: false },
...menuData.data,
...proData.pageData
},
...menuData.Methods,
...proData.methods,
/**
* 生命周期函數(shù)--監(jiān)聽(tīng)頁(yè)面加載
*/
onLoad: function (options) {
},
/**
* 生命周期函數(shù)--監(jiān)聽(tīng)頁(yè)面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函數(shù)--監(jiān)聽(tīng)頁(yè)面顯示
*/
onShow: function () {
},
/**
* 生命周期函數(shù)--監(jiān)聽(tīng)頁(yè)面隱藏
*/
onHide: function () {
},
/**
* 生命周期函數(shù)--監(jiān)聽(tīng)頁(yè)面卸載
*/
onUnload: function () {
},
/**
* 頁(yè)面相關(guān)事件處理函數(shù)--監(jiān)聽(tīng)用戶下拉動(dòng)作
*/
onPullDownRefresh: function () {
/* wx.showLoading({
title: '正在加載...',
});
setTimeout(()=>{
wx.stopPullDownRefresh,
wx.hideLoading();
},2000) */
},
/**
* 頁(yè)面上拉觸底事件的處理函數(shù)
*/
onReachBottom: function () {
/* wx.showToast({
title: '沒(méi)有更多數(shù)據(jù)',
}) */
let that =this
that.getHttpProductMore();
},
/**
* 用戶點(diǎn)擊右上角分享
*/
onShareAppMessage: function () {
}
})
searchFoodData.js:
var httpClient = require('../utils/HttpClient.js');
var tools = require('../utils/util.js');
import url from "../utils/apiUrl.js"
var pageData = {
inputValue:{},
searchData:{},
searchLen:'',
clickEnter:'0',
};
var ispage = true;
var indexpage = 1;//頁(yè)數(shù)默認(rèn)為1
var methods = {
//分頁(yè)
getHttpProductMore: function () {
var self = this;
if (ispage) {
ispage = false;//沒(méi)有下一頁(yè)ispage 賦值為false
indexpage++; //頁(yè)數(shù)加1
let searchData= this.data.inputValue.value//獲取輸入框的值
//console.log('頁(yè)',indexpage);
wx.showLoading({
title: '正在加載...',
});
httpClient.get(url.getSearchVegetables+"?cid="+"&Key="+searchData+"&pageId="+indexpage).then(function (o) {
//console.log("更多的數(shù)據(jù)",o);
if (o.length > 0) {//如果長(zhǎng)度大于0,使用concat連接起來(lái),ispage賦值為true
var tempData = self.data.searchData;
tempData = tempData.concat(o)
self.setData({ searchData: tempData })
ispage = true;
wx.hideLoading()
}
else {
wx.showToast({
title: '沒(méi)有更多了',
});
indexpage = 1;
}
});
}
},
search(e){
ispage = true
wx.showLoading({
title: '正在加載...',
});
let searchData= this.data.inputValue.value
console.log('搜索的數(shù)據(jù)',searchData);
let that=this
let clickEnter=1
httpClient.get(url.getSearchVegetables+"?cid="+"&Key="+searchData+"&pageId=1").then(function(r){
wx.hideLoading();
//console.log("搜索數(shù)據(jù)",r);
let searchData=r
let searchLen=r.length
that.setData({
searchData,
searchLen,
clickEnter
})
})
} ,
changeModel(e){
let data={};
data[e.currentTarget.dataset.key] = e.detail.value
this.setData({
inputValue:data
})
//console.log(data);
// console.log('data',this.data.inputValue);
} ,
jumpVegetables(e){
const {cid}=e.currentTarget.dataset
wx.navigateTo({
url: '/pages/vegetable-index/vegetable-index?cid='+cid,
success: (result)=>{
},
});
}
}
module.exports = {
pageData: pageData,
methods: methods
}
總結(jié)
到此這篇關(guān)于微信小程序之搜索分頁(yè)功能的實(shí)現(xiàn)代碼的文章就介紹到這了,更多相關(guān)小程序搜索分頁(yè)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- 微信小程序?qū)崙?zhàn)之上拉(分頁(yè)加載)效果(2)
- 微信小程序分頁(yè)加載的實(shí)例代碼
- 微信小程序云開(kāi)發(fā)實(shí)現(xiàn)數(shù)據(jù)添加、查詢和分頁(yè)
- 微信小程序模板之分頁(yè)滑動(dòng)欄
- 微信小程序?qū)崿F(xiàn)移動(dòng)端滑動(dòng)分頁(yè)效果(ajax)
- 微信小程序?qū)崿F(xiàn)分頁(yè)加載效果
- 微信小程序?qū)崿F(xiàn)瀑布流分頁(yè)滾動(dòng)加載
- 微信小程序?qū)崿F(xiàn)下拉刷新和上拉分頁(yè)效果的方法詳解
- 微信小程序?qū)崿F(xiàn)分頁(yè)查詢?cè)斀?/a>
- 微信小程序?qū)崿F(xiàn)本地分頁(yè)加載
相關(guān)文章
SpringBoot2零基礎(chǔ)到精通之異常處理與web原生組件注入
SpringBoot是Spring全家桶的成員之一,基于約定優(yōu)于配置的思想(即有約定默認(rèn)值,在不配置的情況下會(huì)使用默認(rèn)值,在配置文件下配置的話會(huì)使用配置的值)。SpringBoot是一種整合Spring技術(shù)棧的方式(或者說(shuō)是框架),同時(shí)也是簡(jiǎn)化Spring的一種快速開(kāi)發(fā)的腳手架2022-03-03
JPA如何將查詢結(jié)果轉(zhuǎn)換為DTO對(duì)象
這篇文章主要介紹了JPA如何將查詢結(jié)果轉(zhuǎn)換為DTO對(duì)象,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-02-02
Swagger3.0 整合spring boot2.7x避免swagger2.0與boot2.7沖突
這篇文章主要介紹了Swagger3.0 整合spring boot2.7x避免swagger2.0與boot2.7沖突問(wèn)題,通過(guò)注釋掉2.0引入的倆包,直接引入3.0,文中結(jié)合實(shí)例代碼給大家介紹的非常詳細(xì),需要的朋友參考下吧2023-10-10
Java中Collections.sort()排序方法舉例詳解
很多時(shí)候都需要對(duì)一些數(shù)據(jù)進(jìn)行排序的操作,這篇文章主要給大家介紹了關(guān)于Java中Collections.sort()方法舉例詳解的相關(guān)資料,使用Collections.sort()可以使用其sort()方法來(lái)對(duì)List、Set等集合進(jìn)行排序,需要的朋友可以參考下2024-02-02
Java操作另一個(gè)Java程序使其重啟的簡(jiǎn)單實(shí)現(xiàn)
下面小編就為大家?guī)?lái)一篇Java操作另一個(gè)Java程序使其重啟的簡(jiǎn)單實(shí)現(xiàn)。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-03-03
java實(shí)現(xiàn)簡(jiǎn)單汽車租賃系統(tǒng)
這篇文章主要為大家詳細(xì)介紹了java實(shí)現(xiàn)簡(jiǎn)單汽車租賃系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-01-01
java中的內(nèi)部類內(nèi)部接口用法說(shuō)明
這篇文章主要介紹了java中的內(nèi)部類內(nèi)部接口用法說(shuō)明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-09-09

