小编给大家分享一下微信小程序如何实现搜索功能并跳转搜索结果页面,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!

微信小程序实现搜索功能,并跳转搜索结果页面,具体内容如下
搜索页面:
search.wxml页面:
search.wxss样式:
.form {
position: relative;
height: 40px;
}
.searchInput {
border: 1px solid #2c3036;
height: 40px;
line-height: 40px;
font-size: 14px;
border-radius: 20px;
color: #bebec4;
padding-left: 35px;
}search.js:
// 搜索
goSearch: function(e) {
var that = this;
var formData = e.detail.value;
if (formData) {
wx.request({
url: 'https://xxxxx/homepage/search',
data: {
title: formData
},
header: {
'Content-Type': 'application/json'
},
success: function(res) {
that.setData({
search: res.data,
})
if (res.data.msg=='无相关视频'){
wx.showToast({
title: '无相关视频',
icon: 'none',
duration: 1500
})
}else{
let str = JSON.stringify(res.data.result.data);
wx.navigateTo({
url: '../searchShow/searchShow?data=' + str
})
}
// console.log(res.data.msg)
}
})
} else {
wx.showToast({
title: '输入不能为空',
icon: 'none',
duration: 1500
})
}
}搜索结果:
searchShow.wxml页面:
searchShow.js onLoad: function(options) { let searchShow = JSON.parse(options.data); let that = this that.setData({ searchShow: searchShow }) console.log(searchShow) }, {{item.title}} {{item.decription}}
以上是“微信小程序如何实现搜索功能并跳转搜索结果页面”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注创新互联行业资讯频道!