微信小程序 和 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 (){} 但是在使用时触发完全没有反应,后来尝试给外层加了一个高度,解决问题 仔细想想也是,没有设 ...
- 微信小程序(五) 利用模板动态加载数据
利用模板动态加载数据,其实是对上一节静态数据替换成动态数据:
随机推荐
- CF1229D - Wojtek and Card Tricks
做法一 首先将排列用康托展开映射到整数,并且预处理出排列之间乘法的结果,复杂度 \(\mathcal{O}(k(k!) ^ 2)\). 枚举左端点,有可能分段的右端点至多只有 \(k!\) 个,不妨将 ...
- Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile
前言 IDEA(2020)引入Maven进行依赖管理,无法从私服上下载jar包 报如下错误 Failed to execute goal org.apache.maven.plugins:maven- ...
- Maven系列--"maven-compiler-plugin"的使用
万分感谢大佬:Poorzerg 原文链接:https://my.oschina.net/poorzerg/blog/206856 maven是个项目管理工具,如果我们不告诉它我们的代码要使用什么样的j ...
- linux 进程信号
转载请注明来源:https://www.cnblogs.com/hookjc/ signal 函数的使用方法简单,但并不属于 POSIX 标准,在各类 UNIX 平台上的实现不尽相同,因此其用途受 到 ...
- css最终章之浮动、定位、溢出属性处理、z-index属性、透明度
上期内容回顾 CSS简介 # 主要就是给HTML标签添加样式 # 固定语法结构 选择器 {属性名1:属性值;属性名2:属性值} 三种引用方式 1.link标签引入外部css文件(最正规) 2.HTML ...
- 枚举和注解@override、@Deprecated、@SuppressWarnings
一.枚举 简介: 1)枚举对应英文(enumeration,简写 enum) 2)枚举是一组常量的集合. 3)可以这里理解:枚举属于一种特殊的类,里面只包含一组有限的特定的对象. 实现方式: 1.自定 ...
- 面试题之java缓存总结,从单机缓存到分布式缓存架构
1.缓存定义 高速数据存储层,提高程序性能 2.为什么要用缓存(读多写少,高并发) 1.提高读取吞吐量 2.提升应用程序性能 3.降低数据库成本 4.减少后端负载 5.消除数据库热点 6.可预测的性能 ...
- MyBatis加强(4)~mybatis 插件开发
一.插件介绍[动态代理] 1.插件[动态代理]:mybatis 允许在已经映射的语句的执行过程的某个时机进行拦截增强的机制. 2.mybatis中的组件动态代理的运用: MyBatis 在四大组件对象 ...
- Solution -「ABC 215H」Cabbage Master
\(\mathcal{Description}\) Link. 有 \(n\) 种颜色的,第 \(i\) 种有 \(a_i\) 个,任意两球互不相同.还有 \(m\) 个盒子,每个盒子可以被放 ...
- Cesium 加载地形数据
1.注册Cesium Ion账号,注册地址:Sign In | Cesium ion 否则,加载数据会报错{code: "InvalidCredentials", message: ...