在改造项目的过程中,遇到个问题,page.json中的标题是写死的,那么能否根据同一页面,不同商品显示不同标题呢?
第一步:将page.json路由中的"navigationBarTitleText": "",置空,如下:
javascript
{
"root": "pages/goods_details",
"name": "goods_details",
"pages": [{
"path": "index",
"style": {
"navigationBarTitleText": "",//商品详情
"navigationStyle": "custom"//自定义tabbar
}
}
]
},
{
"path": "discoverDetails/index",
"style": {
"navigationBarTitleText": "",//内容详情
"navigationBarBackgroundColor": "#ffffff",
"app-plus": {
// #ifdef APP-PLUS
"titleNView": {
"type": "default"
}
// #endif
}
}
},
步骤二:拿到详情接口,给每个商品详情赋值标题
javascript
getInfo(){
接口Api(this.community_id).then(res=>{
this.infoData = res.data;
//内容标题
uni.setNavigationBarTitle({
title: res.data.title.substring(0, 13) + '...'
});
// #ifdef H5
this.ShareInfo();
// #endif
}).catch(err => {
return this.$util.Tips({
title: err
});
});
},