uniapp中vue router界面的上拉刷新和下拉加载更多

基于jeecgboot app 修改,因使用了uni simple router 做了完整的路由控制,整个app就一个index.vue是个页面,其他的都成了组件,uniapp中对页面设置的上拉也不能用了,修改如下:
page.json中index加上可刷新

{
			"path": "pages/index/index",
			"style": {
				"enablePullDownRefresh": true
			}
		},

index.vue

<template>
	<view>
		<!-- <home :cur="PageCur" v-if="PageCur=='home'" :key="commponent1Key"></home> -->
		<myorders  v-if="PageCur=='myorders'" :key="commponent1Key"></myorders>
		<reservelist  v-if="PageCur=='reservelist'" :key="commponent2Key" :refresh="refresh" @refreshOver="overRefresh" :more="more" @moreOver="overMore"></reservelist>
		<people v-if="PageCur=='people'" :key="commponent3Key"></people>
		<view class="cu-bar tabbar bg-white shadow foot">
			<view :class="PageCur=='myorders'?'action text-green':'action text-gray'" @click="NavChange" data-cur="myorders">
				<view class='cuIcon-pay'></view>订单
			</view>
			<view :class="PageCur=='reservelist'?'action text-green':'action text-gray'" @click="NavChange" data-cur="reservelist">
				<view class='cuIcon-list'></view>预约记录
			</view>
			<view :class="PageCur=='people'?'action text-green':'action text-gray'" @click="NavChange" data-cur="people">
				<view class='cuIcon-people'></view>个人
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
		return {
				PageCur: 'myorders',
				commponent1Key: 0,
				commponent2Key: 0,
				commponent3Key: 0,
				refresh:false,
				more:false
			}
		},
		onLoad:function(){
			let cur = this.$Route.query.cur
			if(cur){
				this.PageCur = cur 
			}else{
				this.PageCur = 'myorders'
			}

			++this.commponent1Key
			++this.commponent2Key
			++this.commponent3Key
		},
		onPullDownRefresh() {
			console.log('begin fresh')
			this.refresh = true
		},
		onReachBottom(){
			console.log('begin more')
			this.more = true
		},
		methods: {
			NavChange: function(e) {
				this.PageCur = e.currentTarget.dataset.cur
			},
			overRefresh(){
				uni.stopPullDownRefresh()
				this.refresh = false
				console.log('end fresh')
			},
			overMore(){
				this.more = false
				console.log('over more')
			}
			
		}
	}
</script>

<style>

</style>

子控件reservelist 中

<template>
	<view>
		<cu-custom bgColor="bg-gradual-blue">
			<block slot="content">预约记录</block>
		</cu-custom>
		<scroll-view>
			<view v-for="(item) in dataSource" :key="item.id">
			<view class="cu-card article" :class="isCard?'no-card':''">
						<view class="cu-item shadow">
							<view class="title"><view class="text-cut">{{item.title}}</view></view>
							<view class="content">
								<view class="desc">
									
									
								</view>
							</view>
						</view>
					</view>
			</view>
		</scroll-view>
		<view class="cu-tabbar-height margin-top"></view>
	</view>
</template>

<script>
	import Tips from '@/common/util/tip.js'
	import {
		http
	} from '@/common/service/service.js'
	export default {
		name: 'reservelist',
		props: {
			refresh: {
				type: Boolean,
				default: false
			},
			more: {
				type: Boolean,
				default: false
			}
		},
		data() {
			return {
				dataSource: [],
				ipagination: {
					current: 1,
					pageSize: 3,
					total: 0
				}
			}
		},
		created() {
			this.loadData()
		},
		watch: {
			refresh(val) {
				if (val) {
					this.ipagination.current=1
					this.loadData()
					this.$emit('refreshOver')
				}
			},
			more(val) {
				if (val) {
					if(this.ipagination.total>this.dataSource.length){
						this.ipagination.current++
						this.loadData()
					}
					// this.$emit('moreOver')
				}
			}
		},
		methods: {
			loadData() {
				let p={
					pageNo:this.ipagination.current,
					pageSize:this.ipagination.pageSize
				}
				http.request({
					method: 'GET',
					url: '/meet/reserve/reserveRoom/listReserveForH5',
					data:p
				}).then(res=>{
					if(res.data.success){
						let ds = res.data.result.records
						this.ipagination.total = res.data.result.total
						if(this.ipagination.current==1){
							this.dataSource = ds
						}else{
							ds.forEach(row=>{
								this.dataSource.push(row)
							})
						}
					}else{
						Tips.error(res.data.message)
					}
				}).finally(()=>{
					this.$emit('moreOver')
				})
			},
			totest() {
				this.$Router.push({
					name: 'home'
				})
			}
		}
	}
</script>

<style>

</style>

这样简单的一级页面和二级组件还好些,如果组件中再跳转三级组件,那就麻烦了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值