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