uniapp 返回上一级 刷新页面

在A页面点击跳转B页面,后返回到A页面 要求A页面数据刷新

方法一:onShow

在onShow中再次调用需要刷新的数据

onShow() {
	this.方法名	   
},

方法二:uni.navigateBack()

A页面监听了一个名为refreshPage的事件,当B页面返回时,A页面会收到通知并执行刷新操作

这个方法也可以适用于当返回到A页面时需要传递参数

在A页面

onShow() {
  uni.$on('refreshPage', this.refreshPage);
},
onHide() {
  uni.$off('refreshPage', this.refreshPage);
},
methods: {
  refreshPage() {
    // 执行刷新操作
    this.loadData();
  },
  loadData() {
    // 加载数据的方法
  }
},
uni.navigateback({
    delta:1.
    success(){
      // 发送事件通知上一页更新数据
       uni.$emit('refreshPage', {});
})

方法三:v-if 

这个方法适用于A页面使用了组件,从组件当中跳转到B页面

在A页面的整个页面的头部 加上v-if 

<div v-if="show">
这里是你页面要显示的东西
<div>

methods: {
        init() {
			this.show=false
			//这里写需要调用的数据
            this.UserLogin()
			setTimeout(()=>{
				this.show=true
			},50)
			
		},

猜你喜欢

转载自blog.csdn.net/lingrer/article/details/138351585