fix: 修复网页标题设置逻辑,统一参数传递格式
1. 将enable_set_title的布尔判断改为数字1/0的格式,统一前后端参数传递规则 2. 重构导航栏标题更新逻辑,抽离为公共方法并监听title和enableSetTitle变化 3. 新增onShow钩子触发标题更新,修复页面重新显示时标题不刷新的问题 4. 补充控制台日志用于调试跳转链接参数
This commit is contained in:
@@ -637,13 +637,13 @@ export default {
|
||||
// 公共参数
|
||||
const params = {
|
||||
title: link?.title ?? '',
|
||||
enable_set_title: Boolean(link?.enable_set_title)
|
||||
enable_set_title: link?.enable_set_title ? 1 : 0
|
||||
}
|
||||
|
||||
// #ifdef H5
|
||||
let url = this.normalizeUrl(decodeEntity(link.wap_url));
|
||||
url = this.appendQueryParams(url, params);
|
||||
// console.log(`url ---->`, url)
|
||||
// console.log(`url ---->`, url, link)
|
||||
window.location.href = url;
|
||||
// #endif
|
||||
|
||||
|
||||
@@ -73,7 +73,7 @@ export default {
|
||||
|
||||
// #ifdef H5
|
||||
this.formTitle = options?.title ?? '';
|
||||
this.enableSetTitle = Boolean(options?.enable_set_title);
|
||||
this.enableSetTitle = options?.enable_set_title == 1;
|
||||
// #endif
|
||||
|
||||
this.uniacid = options.uniacid
|
||||
|
||||
@@ -21,7 +21,7 @@ export default {
|
||||
},
|
||||
onLoad(option) {
|
||||
this.title = option?.title ?? '';
|
||||
this.enableSetTitle = Boolean(option?.enable_set_title);
|
||||
this.enableSetTitle = option?.enable_set_title == 1;
|
||||
|
||||
// #ifdef H5
|
||||
this.src = decodeEntity(decodeURIComponent(option.src));
|
||||
@@ -32,10 +32,17 @@ export default {
|
||||
// #endif
|
||||
},
|
||||
onReady() {
|
||||
if (this.enableSetTitle) {
|
||||
uni.setNavigationBarTitle({
|
||||
title: this.title
|
||||
});
|
||||
this.updateNavbarTitle();
|
||||
},
|
||||
onShow() {
|
||||
this.updateNavbarTitle();
|
||||
},
|
||||
watch: {
|
||||
title(newVal) {
|
||||
this.updateNavbarTitle(newVal);
|
||||
},
|
||||
enableSetTitle() {
|
||||
this.updateNavbarTitle();
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
@@ -43,6 +50,13 @@ export default {
|
||||
uni.navigateBack({
|
||||
delta: 1
|
||||
});
|
||||
},
|
||||
updateNavbarTitle(newTitle) {
|
||||
if (this.enableSetTitle) {
|
||||
uni.setNavigationBarTitle({
|
||||
title: newTitle ?? this.title
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user