首页代码 index.vue
<template>
<view>
<button type="default" @click="clickIt()">点我进入B页</button>
<button style="margin-top: 50rpx;" type="default" @click="add()">点我!点击次数{{num}}</button>
</view>
</template>
<script>
export default {
data() {
return {
title: 'watchReFresh',
num:0,
reFresh:""
}
},
watch:{
//监听reFresh,如果有修改就执行监听器
reFresh:function(){
//初始化参数
this.num = 0
//刷新页面(即onLoad里的某些操作
this.num = "110"
console.log("页面已重新加载");
}
},
onLoad() {
this.num = "110"
},
methods: {
clickIt:function(){
uni.navigateTo({
url:'./B'
})
},
add:function(){
this.num ++
}
}
}
</script>
<style>
</style>
第二页代码 B.vue
<template>
<view>
<button type="default" @click="gotoPre()">返回上一页</button>
</view>
</template>
<script>
export default {
data() {
return {
}
},
methods: {
gotoPre:function(){
let pages = getCurrentPages()//页面栈
let prePage = pages[pages.length - 2]//上一页
prePage.$vm.reFresh = Math.random()//触发上一页监听器
uni.navigateBack()//返回上一页
}
}
}
</script>
<style>
</style>