这是pages.json
{
"pages": [
{
"path": "pages/home/home",
"style": {
"navigationBarTitleText": "首页"
}
},
{
"path": "pages/category/category",
"style": {
"navigationBarTitleText": "分类"
}
},
{
"path": "pages/plant/list",
"style": {
"navigationBarTitleText": "列表"
}
},
{
"path":"pages/plant/detail",
"style": {
}
}
],
"globalStyle": {
"navigationBarTextStyle": "#FFF",
"navigationBarTitleText": "首页",
"navigationBarBackgroundColor": "#FFF",
"onReachBottomDistance":100,
"backgroundColor": "#FFF",
"app-plus": {
"background": "#FFF",
"titleNView":false
}
},
// 配置tabbar导航栏
"tabBar": {
"borderStyle": "#FFF",
"selectedColor": "#16811D",
"backgroundColor":"#FFF",
"color": "#999999",
"list": [
{
"pagePath": "pages/home/home",
"iconPath": "static/icon/img/home.png",
"selectedIconPath": "static/icon/img/home-check.png",
"text": "首页"
},{
"pagePath": "pages/category/category",
"iconPath": "static/icon/img/category.png",
"selectedIconPath": "static/icon/img/category-check.png",
"text": "分类"
},{
"pagePath": "pages/plant/list",
"iconPath": "static/icon/img/list.png",
"selectedIconPath": "static/icon/img/list-check.png",
"text": "列表"
}
]
}
}
这是页面
<template>
<view class='plant-list-tabber'>
<view class='plant-search'>
<!-- <uni-easyinput v-model="plantName" focus placeholder="自定义样式" @input="input"
:styles="styles" :placeholderStyle="placeholderStyle" /> -->
</view>
<view class='plant-list-wapper'>
<view @click="openDetail(plant.plantId)" class='plant-list-content' v-for='plant in plants' >
<view class='plant-list-img'>
<img :src='"http://localhost/dev-api"+plant.img' />
</view>
<view class='plant-list-text'>
<view class='plant-name'>{{plant.plantName}}</view>
<view class='plant-subject-attribute'>
<view>{{plant.subjectName}}</view>
<view style="margin-left: 10px;">{{plant.attributeName}}</view>
</view>
<view style="color:darkgrey">{{plant.distributionName}}</view>
<view style="width: 100%;height: 10px;"></view>
</view>
</view>
</view>
</view>
</template>
<script>
export default{
data(){
return {
plants:[],
placeholderStyle: "color:#499721;font-size:16px",
styles: { color: 'blue',borderColor: 'green' },
pageNo:1,
pageSize:10,
pageCount:0,
param:{},
}
},
onLoad() {
this.getList();
},
onReachBottom(){
alert(1);
},
methods:{
getList(){
let that = this;
uni.request({
url:"http://192.168.0.105:2090/wechat/applet/plant/list",
method:"POST",
data:{
pageNo:that.pageNo,
pageSize:that.pageSize,
param:that.param
},
success:function(result){
if(result.data.code == 200){
that.plants = result.data.data.datas;
}
},
error:function(error){
console.log('错误信息',error);
}
})
},
openDetail(plantId){
uni.navigateTo({
url:'../plant/detail?plantId='+plantId,
fail (error) {
console.log('错误信息');
console.log(error)
}
})
}
}
}
</script>
<style scoped>
.plant-list-tabber{
width: 100%;
height: 100%;
background-color: #FFF;
}
.plant-list-wapper{
width: 100%;
height: 100%;
}
.plant-list-wapper{
width: 100%;
height: 100%;
display: flex;
justify-content: left;
flex-wrap: wrap;
}
.plant-list-content{
width: 48%;
height: auto;
padding: 0px 1%;
}
.plant-list-img{
width: 100%;
height: 100px;
}
img{
max-width: 100%;
max-height: 100%;
width: auto;
height: auto;
border-radius: 20px;
}
.plant-list-text{
width: 90%;
height: auto;
padding: 0px 10%;
}
.plant-name{
font-weight: bold;
line-height: 25px;
color:rebeccapurple;
}
.plant-subject-attribute{
display: flex;
justify-content: left;
color: darkgrey;
}
</style>
为什么onReachBottom无效?作为一个后端写前端真头大
根据参考资料和问题描述,可以看出在uniapp中使用onReachBottom方法遇到了问题。根据段落1中的代码,我们可以得出以下结论和解决方案:
根据以上分析,可以按以下方式来修改问题中的代码:
// 相关的.html文件
<template>
<view>
<view class="dataInfo">
<view class="list" v-for="(item, index) in dataList" :key='index'>
<text>{{index}}</text>
<text>{{item}}</text>
</view>
</view>
</view>
</template>
// 相关的.js文件
<script>
import {
indexListData,
} from '@/api/index.js';
export default {
data() {
return {
dataList: [],
total: null,
data: {
pageNum: 1,
pageSize: 5,
}
}
},
mounted() {
this.getList();
},
methods: {
getList() {
indexListData(this.data).then(res => {
if (res.rows) {
this.dataList = [...this.dataList, ...res.rows];
}
this.total = res.total;
})
},
onReachBottom() {
// 当数组里的数据大于等于total的时候,说明数据已经加载完了
if (this.dataList.length >= this.total) {
setTimeout(() => {
uni.showToast({
title: '没有更多数据了',
icon: 'none',
duration: 1000
});
uni.hideLoading();
}, 500);
} else {
// 每次上拉加载的数据比上一次多十个
this.data.pageNum++;
uni.showLoading({
title: '加载中'
});
this.getList();
setTimeout(() => {
uni.hideLoading();
}, 500);
}
},
}
}
</script>
请测试以上代码修改是否能解决该问题。