1.从其他界面返回
点击提交按钮或者其他按钮,操作完毕,
返回上一个界面的方法:
[detail.vue]:
submit() {
...
window.history.back()
}
2.主界面监听并重新获取数据从而刷新
[mainList.vue]:
watch: {
$Route(to, from ) {
const fname = from.name
const tname = to.name
console.log('界面切换,从:', from.name, '到当前界面:', to.name)
this.query()
}
},
3.可以在其他界面设置meta变量
从而确定返回主界面后,是否刷新主届面。
[common/router/modules/routes.js]:
const routes = [
{
path: "/pages/detail",
name: "detal",
meta: {
title: "详情界面",
isRefresh: true,
},
},
...
]
4.在主界面获取该变量做判断
[mainList.vue]:
watch: {
$Route(to, from ) {
const fname = from.name
const tname = to.name
console.log('界面切换,从:', from.name, '到当前界面:', to.name)
if (true = from.name.isRefresh) {
this.query()
}
}
},
本文介绍了如何通过Vue.js实现页面间的导航返回及主界面数据的自动刷新。具体包括使用window.history.back()进行页面回退、监听路由变化并执行查询刷新、设置meta变量控制刷新行为等方法。
1489

被折叠的 条评论
为什么被折叠?



