使用vue来做app内嵌的头部导航,整体思路:在app.vue页面下保存访问过的路由到数组,watch监听路由变化改变路由及标题,头部导航返回调用goBack(),原生返回需要和app商量,我这边调用的是app处理过的window.postMessage
一、头部导航代码如下
<div>
<img @click="goBack()" src="返回按钮" alt="">
{
{commonTitle}}
</div>
二、首次进入内嵌页保存当前路由到routeList: [],switch判断当前标题信息,新建变量commonTitle 来显示标题
created(){
var routePath = this.$route.path;
this.routeList.push(routePath);
switch(routePath){
case '/':
this.commonTitle = '首页';
break;
case '/list':
this.commonTitle = '列表页';
break;
case '/listInfo':
this.commonTitle = '详情页';
break;
}
}
三、切换路由时watch监听$route.path保存当前路由到routeList: [],
watch: {
'$route.path': function (n