search

Home  >  Q&A  >  body text

`<server-only>` tag for server-side rendering only

<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粉463811100P粉463811100485 days ago439

reply all(1)I'll reply

  • P粉724737511

    P粉7247375112023-08-30 13:02:38

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

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

    Hope this will help me out again...

    reply
    0
  • Cancelreply