uniapp返回上一页并刷新数据

在uniapp中,返回页面时onLoad是不会触发的

如果只需要在特定情况下返回上一页才需要刷新数据

可以使用$emit和$no去解决

例如:注册完成后返回到首页并隐藏注册按钮,register.vue和index.vue

register.vue

html 复制代码
<template>
	<view @click="register">立即注册</view>
</template>

<script>
export default {
	methods: {
		register(){
			uni.$emit('register_refresh')
			uni.navigateBack({
				delta: 1
			});
		}
	}
}
</script>

index.vue

html 复制代码
<script>
export default {
	onLoad() {
		// 正常进入页面触发
		this.is_login()
		// 注册完成后返回触发
		uni.$on('register_refresh', () => {
			// 执行需要隐藏的按钮,
			this.is_ever = false
			// 请求用户登陆注册状态
			this.is_login()
		})
	}
}
</script>
相关推荐
Lank_M1 小时前
白底都占八成,PNG 为何只在图表页赢过 JPG
前端
张一凡932 小时前
给 Coding Agent 加一道"架构闸门":Jin 是如何做到"先审架构、再写代码、不漂移"的
前端·后端·agent
Linye2 小时前
AI 写的 HTML 原型全是空壳?聊聊真实 DOM 交互避坑
前端·人工智能
ZANE2 小时前
纯前端实现的 PDF 与图片互相转换工具技术实现
前端
Swot2 小时前
SvelteKit Remote Functions 使用指南
前端·后端
Cooper252 小时前
三源热榜去重加 AI 摘要:URL 唯一键踩出的三个坑
前端·python
Yk酱228402 小时前
A2UI探索随笔-技术选型
前端
前端繁华如梦2 小时前
# 从 73000 行压缩代码到 TypeScript 模块化:我把一个 Three.js FPS 游戏 1:1 复刻了一遍
前端
Penge6663 小时前
React Context 详解:从 Props 传递到跨组件状态共享
前端
Penge6663 小时前
React 事件处理:bind(this) 原理与实际开发常用写法
前端