`<server-only>` tag for server-side rendering only
P粉463811100
P粉463811100 2023-08-29 20:30:07
0
1
340
<p>I have some code that only needs to be rendered on the client side, so I wrap it in a <code><client-only></code> tag. </p> <p>However, to prevent the content from bouncing, I tried rendering the element only on the server side, using the following code: </p> <pre class="brush:php;toolbar:false;"><div v-if="$isServer" class="h-nonav bg-gray-500" /></pre> <p>This does work, but Vue will complain that the server-side HTML is inconsistent with the client-side. </p> <p>While this works, it sounds a bit hackish and will cause the page to be rendered twice: </p> <pre class="brush:php;toolbar:false;"><div v-if="ssr" class="h-nonav bg-gray-500" /> ... data() { return { ssr: true } }, mounted() { this.ssr = false },</pre> <p>Trying to search the documentation, but the <code><server-only></code> tag was not found :(</p>
P粉463811100
P粉463811100

reply all(1)
P粉724737511

Never mind, using v-show instead of v-if fixed it:

<div v-show="$isServer" />

Hope this will help me out again...

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!