微信小程序 和 laravel8 实现搜索后分页 加载
Page({
/**
* 页面的初始数据
*/
data: {
activity:{},
page:1,
last_page : 0,
keyword:''
},
//加载
scroll(e){
let that = this;
let page = that.data.page+1;
let keyword = that.data.keyword
that.setData({
page:page
})
let last_page = that.data.last_page
if(page > last_page){
wx.showToast({
title: '到底了',
})
return ;
}
wx.showLoading({
title: '加载中',
})
wx.request({
url: 'http://www.week2.skill.com/api/activity/index',
data:{page,keyword},
header: {
'content-type': 'application/json' // 默认值
},
success (res) {
console.log(res.data)
let activity = res.data.data.data
that.setData({
activity:that.data.activity.concat(activity),
})
wx.hideLoading()
}
})
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
var that = this;
wx.request({
url: 'http://www.week2.skill.com/api/activity/index',
header: {
'content-type': 'application/json' // 默认值
},
success (res) {
console.log(res.data)
let activity = res.data.data.data
that.setData({
activity:activity,
last_page:res.data.data.last_page,
page:res.data.data.current_page
})
}
})
},
//搜索
dopost:function(e){
console.log(e);
let formData = e.detail.value;
wx.request({
url: 'http://www.week2.skill.com/api/activity/index',
data:formData,
method:"GET",
success:res=>{
console.log(res);
if(res.data.status==200){
this.setData({
activity:res.data.data.data,
keyword:formData.keyword,
last_page:res.data.data.last_page,
page:res.data.data.current_page
})
}
},
fail(e){
wx.showToast({
title: '请求失败',
icon:"error"
})
}
})
},
})
控制器:
/**
* 查询数据 分页展示
* @param Request $request
* @return array
*/
public function index(Request $request)
{
$keyword = $request->input('keyword');
$data = Activity::when($keyword,function ($query,$keyword){
return $query->where('title','like','%'.$keyword.'%');
})->select('title','img','surplus_number')->paginate(5);
return ['status'=>200,'msg'=>'success','data'=>$data];
}
wxml:
<view>
<view>
<view>
<form bindsubmit="dopost">
<view class="weui-search-bar">
<view class="weui-search-bar__form">
<!-- 搜索框 -->
<view class="weui-search-bar__box">
<icon class="weui-icon-search_in-box" type="search" size="14"></icon>
<input type="text" name="keyword" value="{{keyword}}" class="weui-search-bar__input" placeholder="请输入搜索内容" />
</view>
</view>
<!-- 搜索按钮,调用搜索查询方法 -->
<button size="mini" class="weui-search-bar__cancel-btn" form-type="submit">搜索</button>
</view>
</form>
</view>
</view>
<view class="page-section-spacing">
<scroll-view scroll-y="true" class="page-scroll-style" bindscrolltolower="scroll">
<block wx:for="{{activity}}" wx:key="activity">
<view class="scroll-view-content">
<image src="{{item.img}}" class="scroll-view-image"></image>
<view class="scroll-view-text">
{{item.title}}
</view>
<view class="scroll-view-name">
{{item.surplus_number}}
</view>
</view>
</block>
</scroll-view>
</view>
</view>
wxss:
/**index.wxss**/
.weui-search-bar {
position: relative;
padding: 8px 10px;
display: -webkit-box;
display: -webkit-flex;
display: flex;
box-sizing: border-box;
background-color: #EFEFF4;
border-top: 1rpx solid #D7D6DC;
border-bottom: 1rpx solid #D7D6DC;
}
.weui-icon-search_in-box {
position: absolute;
left: 10px;
top: 7px;
}
.weui-search-bar__form {
position: relative;
-webkit-box-flex: 1;
-webkit-flex: auto;
flex: auto;
border-radius: 5px;
background: #FFFFFF;
border: 1rpx solid #E6E6EA;
}
.weui-search-bar__box {
position: relative;
padding-left: 30px;
padding-right: 30px;
width: 100%;
box-sizing: border-box;
z-index: 1;
}
.weui-search-bar__input {
height: 28px;
line-height: 28px;
font-size: 14px;
}
.weui-search-bar__cancel-btn {
margin-left: 10px;
line-height: 28px;
color: #09BB07;
white-space: nowrap;
}
.swp{
height: 500rpx;
}
.page-section-spacing{
margin-top: 60rpx;
} .page-scroll-style{
height: 1000rpx;
background: aliceblue;
}
.scroll-view-content{
height: 230rpx;
margin: auto 10rpx;
background: white;
border: 1px solid gray;
}
.scroll-view-image{
width: 200rpx;
height: 200rpx;
margin-top: 15rpx;
margin-left: 20rpx;
float: left;
}
.scroll-view-text{
width: 400rpx;
float: left;
font-weight: 800;
margin-top: 15rpx;
margin-left: 20rpx;
}
.scroll-view-name{
float: left;
font-size: 30rpx;
color: gray;
margin-top: 20rpx;
margin-left: 20rpx;
}
.scroll-view_H{
white-space: nowrap;
}
.scroll-view-item{
height: 300rpx;
}
.scroll-view-item_H{
display: inline-block;
width: 100%;
height: 300rpx;
}
微信小程序 和 laravel8 实现搜索后分页 加载的更多相关文章
- 微信小程序实现上拉和下拉加载更多
在上一篇文章中,我们知道了使用 scroll-view 可以实现上拉加载更多,但是由于 scroll-view 的限制,它无法实现下拉加载更多,这篇文章我们使用 view 组件来实现 上拉和下拉加载更 ...
- 微信小程序开发--模板(template)使用,数据加载,点击交互
微信小程序视图层提供了 模板(template),可以在模板中定义代码片段,然后在不同的地方调用.结果在数据渲染那懵逼了.按照官网上对模板的说明和对数据的加载. 1.定义模板 使用name属性,作为模 ...
- 微信小程序之下拉刷新,上拉加载更多
近日开发微信小程序,发现上拉加载更多没有友好的API,而下拉刷新很nice,所以本人按照API,很简单的写了一个示例,希望对大家有帮助,本人用的是iview-webapp 小程序UI框架. 1. 首 ...
- 【微信小程序】转载:微信小程序实战篇-下拉刷新与加载更多
下拉刷新 实现下拉刷新目前能想到的有两种方式 1. 调用系统的API,系统有提供下拉刷新的API接口 当然,你可以直接在全局变量app.json的window里面配置上面这个属性,这样整个项目都允许下 ...
- 微信小程序 在使用wx.request时显示加载中
微信小程序中,向后台请求数据是,通常想给用户提示正在加载中,如下图: 我们可以用wx.showLoading(OBJECT),当请求服务器的地方多了,怎么才能不每次都要去调用函数,我们只要对wx.re ...
- 微信小程序实战篇-下拉刷新与加载更多
下拉刷新 实现下拉刷新目前能想到的有两种方式 1. 调用系统的API,系统有提供下拉刷新的API接口 2. 监听scroll-view,自定义下拉刷新,还记得scroll-view里面有一个binds ...
- 微信小程序开发——设置默认图片、错误加载图片
小程序不支持h5中的onerrorimg,只开放了binderror属性,当错误发生时,会发布到 AppService,事件对象event.detail = {errMsg: 'something w ...
- 微信小程序采坑之上拉触底加载更多和下拉刷新
小程序中加载更多数据一般都是触底刷新 有自带的函数: onReachBottom: function (){} 但是在使用时触发完全没有反应,后来尝试给外层加了一个高度,解决问题 仔细想想也是,没有设 ...
- 微信小程序(五) 利用模板动态加载数据
利用模板动态加载数据,其实是对上一节静态数据替换成动态数据:
随机推荐
- NumPy 教程目录
NumPy 教程目录 1 Lesson1--NumPy NumPy 安装 2 Lesson2--NumPy Ndarray 对象 3 Lesson3--NumPy 数据类型 4 Lesson4--Nu ...
- 求一个number数组中的最大值和最小值的差
<!DOCTYPE html> <html> <head> <meta http-equiv="content-type" content ...
- 「JOI 2014 Final」裁剪线
做法一 首先将边界也视作四条裁剪线,整个平面作为一张纸,视存在 \(y = -\infty, y = +\infty, x = -\infty, x = +\infty\) 四条直线. 按照纵坐标依次 ...
- 防火墙——firewalld
介绍 firewald是对于iptables的一个封装,可以让你更容易地管理iptables规则.firewalld是iptables前端控制器,用于实现持久地网络流量规则. 一.对比 firewal ...
- C语言非阻塞式键盘监听
监听键盘可以使用C语言的字符输入函数,例如 getchar.getch.getche 等,使用getche函数监听键盘的例子: #include <stdio.h> #include &l ...
- rust 实战 - 实现一个线程工作池 ThreadPool
如何实现一个线程池 线程池:一种线程使用模式.线程过多会带来调度开销,进而影响缓存局部性和整体性能.而线程池维护着多个线程,等待着监督管理者分配可并发执行的任务.这避免了在处理短时间任务时创建与销毁线 ...
- [GWCTF 2019]babyvm re
BABYVM 基于虚拟机操作的一个题 明面上的check函数和加密逻辑都是假的 操作码 重点分析这个vm 0xF5, 0xF1, 0xE1, 0x00, 0x00, 0x00, 0x00, 0xF2, ...
- Spring Security探究之路之开始
前言 在Spring Security介绍中,我们分析到了根据请求获取匹配的SecurityFilterChain,这个类中包含了一组Filter 接下来我们从这些Filter开始探究之旅 Sprin ...
- 《PHP程序员面试笔试宝典》——如何应对自己不会回答的问题?
如何巧妙地回答面试官的问题? 本文摘自<PHP程序员面试笔试宝典> 在面试的过程中,对面试官提出的问题求职者并不是都能回答出来,计算机技术博大精深,很少有人能对计算机技术的各个分支学科了如 ...
- 02 HTML标签
2. HTML标签 1. HTML简介 用户使用浏览器打开网页看到结果的过程就是:浏览器将服务端的文本文件(即网页文件)内容下载到本地,然后打开显示的过程. 而文本文件的文档结构只有空格和黄航两种组织 ...