diff --git a/pages_tool/webview/webview.vue b/pages_tool/webview/webview.vue index bd9f928..41717d6 100644 --- a/pages_tool/webview/webview.vue +++ b/pages_tool/webview/webview.vue @@ -14,10 +14,15 @@ import { decodeEntity } from '@/common/js/util.js'; export default { data() { return { - src: '' + src: '', + title: '', // 标题栏标题 + enableSetTitle: false, // 是否强制设置标题,用来替换Webview中的默认标题 }; }, onLoad(option) { + this.title = option?.title ?? ''; + this.enableSetTitle = option?.enable_set_title == 1; + // #ifdef H5 this.src = decodeEntity(decodeURIComponent(option.src)); // #endif @@ -26,11 +31,32 @@ export default { this.src = decodeEntity(decodeURIComponent(`${option.src}&from=mp-webview`)); // #endif }, + onReady() { + this.updateNavbarTitle(); + }, + onShow() { + this.updateNavbarTitle(); + }, + watch: { + title(newVal) { + this.updateNavbarTitle(newVal); + }, + enableSetTitle() { + this.updateNavbarTitle(); + } + }, methods: { navigateBack() { uni.navigateBack({ delta: 1 }); + }, + updateNavbarTitle(newTitle) { + if (this.enableSetTitle) { + uni.setNavigationBarTitle({ + title: newTitle ?? this.title + }); + } } } };