Skip to content

Commit 81f8783

Browse files
committed
fix: fix homeview component ssr error
1 parent 784541e commit 81f8783

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/client/modules/home/home.view.vue

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,13 @@ export default class Home extends Vue {
4040
isClientMounted: boolean = false;
4141
4242
private checkIfMobile = () => {
43-
this.isMobile = window.innerWidth < 768;
43+
// 检查是否在浏览器环境中
44+
if (typeof window !== 'undefined') {
45+
this.isMobile = window.innerWidth < 768;
46+
} else {
47+
// 服务端默认为非移动设备
48+
this.isMobile = false;
49+
}
4450
};
4551
4652
private handleResize = () => {
@@ -102,7 +108,9 @@ export default class Home extends Vue {
102108
:isMobile="this.isMobile"
103109
/>
104110
</client-only>
105-
<back-top v-if="!this.isMobile" />
111+
<ClientOnly>
112+
<back-top v-if="!isMobile" />
113+
</ClientOnly>
106114
</div>
107115
</template>
108116

0 commit comments

Comments
 (0)