uniapp返回上一页并刷新数据

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

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

可以使用$emit$no去解决

例如:注册完成后返回到首页并隐藏注册按钮,register.vueindex.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>
相关推荐
咩咩啃树皮24 分钟前
第32篇:前端本地存储全解——Cookie、localStorage、sessionStorage 区别与实战
前端
2501_916008892 小时前
苹果上架工具怎么选 不用 Mac 上架 App Store 的几种方案
android·macos·ios·小程序·uni-app·iphone·webview
腻害兔2 小时前
【若依项目-产品经理视角】深度拆解 RuoYi-Vue-Pro 框架层:15 个 Starter 到底在干什么?
前端·vue.js·产品经理·ai编程
宠友信息2 小时前
MySQL复合索引与Druid优化仿小红书源码个人主页查询链路
数据库·spring boot·websocket·mysql·uni-app
程序员黑豆4 小时前
从零开始:编写第一个鸿蒙(HarmonyOS)程序
前端·harmonyos
lastknight4 小时前
CSS @layer
前端·css
李宸净4 小时前
Web自动化测试selenium+python
前端·python·selenium
淡海水4 小时前
06-04-YooAsset源码-Unity加密解密服务
前端·unity·性能优化·c#·游戏引擎·yooasset
trigger3335 小时前
desk-health-web-community-post
前端