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