chore:微信小程序自定义标题已经可以开始展示了

This commit is contained in:
2026-07-25 15:57:37 +08:00
parent eab5a97ba5
commit 4bd36db70f

View File

@@ -1,6 +1,6 @@
<template>
<view :style="themeColor" class="vr-page">
<web-view :src="src" class="vr-webview" @titleUpdate="updateNavbarTitle"></web-view>
<web-view :src="src" class="vr-webview" @load="onWebViewLoad"></web-view>
</view>
</template>
@@ -27,17 +27,24 @@ export default {
});
},
onShow() {
this.updateNavbarTitle();
if (this.title) {
uni.setNavigationBarTitle({ title: this.title });
}
},
watch: {
title(newVal) {
this.updateNavbarTitle(newVal);
if (newVal) {
uni.setNavigationBarTitle({ title: newVal });
}
}
},
methods: {
updateNavbarTitle(newTitle) {
const title = newTitle ?? this.title;
uni.setNavigationBarTitle({title});
onWebViewLoad() {
if (this.title) {
setTimeout(() => {
uni.setNavigationBarTitle({ title: this.title });
}, 100);
}
}
}
};