chore:自定义标题显示

This commit is contained in:
2026-07-25 17:10:32 +08:00
parent 4bd36db70f
commit a70a29eda1

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" @load="onWebViewLoad"></web-view> <web-view :src="src" class="vr-webview"></web-view>
</view> </view>
</template> </template>
@@ -9,45 +9,53 @@ export default {
data() { data() {
return { return {
src: '', src: '',
title: '' title: '',
titleTimer: null
}; };
}, },
onLoad(option) { onLoad(option) {
this.title = option?.title ?? ''; this.title = option?.title || '工厂展示';
this.$api.sendRequest({ uni.setNavigationBarTitle({ title: this.title });
url: '/api/config/defaultvr', this.$api.sendRequest({
success: res => { url: '/api/config/defaultvr',
if (res.code == 0) { success: res => {
this.src = res.data.url; if (res.code == 0) {
this.title = res.data.title; this.title = res.data.title;
} uni.setNavigationBarTitle({ title: this.title });
}, this.src = res.data.url;
this.startTitleGuard();
}
},
fail: res => { fail: res => {
} }
}); });
}, },
onShow() { onShow() {
if (this.title) {
uni.setNavigationBarTitle({ title: this.title });
}
},
watch: {
title(newVal) {
if (newVal) {
uni.setNavigationBarTitle({ title: newVal });
}
}
},
methods: {
onWebViewLoad() {
if (this.title) { if (this.title) {
setTimeout(() => { uni.setNavigationBarTitle({ title: this.title });
}
},
methods: {
startTitleGuard() {
this.clearTitleGuard();
let count = 0;
this.titleTimer = setInterval(() => {
uni.setNavigationBarTitle({ title: this.title }); uni.setNavigationBarTitle({ title: this.title });
count++;
if (count >= 10) {
this.clearTitleGuard();
}
}, 100); }, 100);
},
clearTitleGuard() {
if (this.titleTimer) {
clearInterval(this.titleTimer);
this.titleTimer = null;
}
} }
} }
} };
};
</script> </script>
<style lang="scss"> <style lang="scss">