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> <template>
<view :style="themeColor" class="vr-page"> <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> </view>
</template> </template>
@@ -27,17 +27,24 @@ export default {
}); });
}, },
onShow() { onShow() {
this.updateNavbarTitle(); if (this.title) {
uni.setNavigationBarTitle({ title: this.title });
}
}, },
watch: { watch: {
title(newVal) { title(newVal) {
this.updateNavbarTitle(newVal); if (newVal) {
uni.setNavigationBarTitle({ title: newVal });
}
} }
}, },
methods: { methods: {
updateNavbarTitle(newTitle) { onWebViewLoad() {
const title = newTitle ?? this.title; if (this.title) {
uni.setNavigationBarTitle({title}); setTimeout(() => {
uni.setNavigationBarTitle({ title: this.title });
}, 100);
}
} }
} }
}; };