fix(vr page): 修复导航栏标题无法正确更新的问题

优化vr页面的导航栏标题更新逻辑,通过监听title变化和监听webview的titleUpdate事件,以及在页面显示时更新标题,确保标题能正确同步显示。
This commit is contained in:
2026-07-25 14:57:22 +08:00
parent 9da07f1566
commit 3d4941865e

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"></web-view> <web-view :src="src" class="vr-webview" @titleUpdate="updateNavbarTitle"></web-view>
</view> </view>
</template> </template>
@@ -8,7 +8,8 @@
export default { export default {
data() { data() {
return { return {
src: '' src: '',
title: ''
}; };
}, },
onLoad(option) { onLoad(option) {
@@ -16,18 +17,28 @@ export default {
url: '/api/config/defaultvr', url: '/api/config/defaultvr',
success: res => { success: res => {
if (res.code == 0) { if (res.code == 0) {
if (res.data?.title) { this.src = res.data.url;
uni.setNavigationBarTitle({ this.title = res.data.title;
title: res.data.title
});
}
this.src = res.data.url
} }
}, },
fail: res => { fail: res => {
} }
}); });
} },
onShow() {
this.updateNavbarTitle();
},
watch: {
title(newVal) {
this.updateNavbarTitle(newVal);
}
},
methods: {
updateNavbarTitle(newTitle) {
const title = newTitle ?? this.title;
uni.setNavigationBarTitle({title});
}
}
}; };
</script> </script>