5 min read
•Question 33 of 37hardWhat is Server-Side Rendering in Vue?
SSR concepts and Nuxt.js.
What You'll Learn
- What is SSR
- SSR benefits
- Nuxt.js overview
What is SSR?
Server-Side Rendering renders Vue components on the server and sends HTML to the client.
Benefits
| Benefit | Description |
|---|---|
| SEO | Search engines can crawl content |
| Performance | Faster first contentful paint |
| Social sharing | Meta tags available immediately |
Basic SSR Flow
code.jsJavaScript
1. Request → Server renders Vue app → HTML
2. Browser receives HTML → Shows content
3. Vue hydrates → App becomes interactiveNuxt.js (Vue SSR Framework)
$ terminalBash
npx nuxi init my-app
cd my-app
npm install
npm run devNuxt Page Example
code.txtVUE
<!-- pages/index.vue -->
<script setup>
const { data } = await useFetch('/api/posts')
</script>
<template>
<div v-for="post in data" :key="post.id">
{{ post.title }}
</div>
</template>Data Fetching
code.jsJavaScript
// Server-side
const { data } = await useFetch('/api/data')
// Client-side only
const { data } = await useFetch('/api/data', {
server: false
})