同一个路由的页面中,涉及到不同的标题名称。例:详情页面包括修改页面,修改页面需更换标题为“编辑详情”,详情页面需要更换标题为“详情”,在pages.json中一个路由配置一个默认标题
问题:
1. 方法:uni.setNavigationBarTitle({ title: ‘编辑详情’})
结果:ios中无法生效,安卓没问题
2. 方法:
dd.setTitle({
title: ‘编辑详情’
}).then(res => {
console.log(res)
}).catch(err => {})
结果:回退,标题覆盖了pages.json中默认配置的,一直为 ''编辑详情''
解决方法:
使用dd.setTitle来改变标题,main.js文件中配置mixin,对路由变化的时候重新设置页面标题
Vue.mixin({
onShow(){
let routes = getCurrentPages()
{ routes.length>0 &&
dd.setTitle({
title: routes[routes.length - 1].$holder.navigationBarTitleText
}).then(res => {
console.log(res)
}).catch(err => {})
}
}
})