@vue/server-renderer
Note: as of 3.2.13+, this package is included as a dependency of the main vue package and can be accessed as vue/server-renderer. This means you no longer need to explicitly install this package and ensure its version match that of vue's. Just use the vue/server-renderer deep import instead.
Basic API
renderToString
Signature
1 | function renderToString( |
Usage
1 | const { createSSRApp } = require('vue') |
Handling Teleports
If the rendered app contains teleports, the teleported content will not be part of the rendered string. Instead, they are exposed under the teleports property of the ssr context object:
1 | const ctx = {} |
Streaming API
renderToNodeStream
Renders input as a Node.js Readable stream.
Signature
1 | function renderToNodeStream(input: App | VNode, context?: SSRContext): Readable |
Usage
1 | // inside a Node.js http handler |
Note: This method is not supported in the ESM build of @vue/server-renderer, which is decoupled from Node.js environments. Use pipeToNodeWritable instead.
pipeToNodeWritable
Render and pipe to an existing Node.js Writable stream instance.
Signature
1 | function pipeToNodeWritable( |
Usage
1 | // inside a Node.js http handler |
renderToWebStream
Renders input as a Web ReadableStream.
Signature
1 | function renderToWebStream( |
Usage
1 | // inside an environment with ReadableStream support |
Note: in environments that do not expose ReadableStream constructor in the global scope, pipeToWebWritable should be used instead.
pipeToWebWritable
Render and pipe to an existing Web WritableStream instance.
Signature
1 | function pipeToWebWritable( |
Usage
This is typically used in combination with TransformStream:
1 | // TransformStream is available in environments such as CloudFlare workers. |
renderToSimpleStream
Renders input in streaming mode using a simple readable interface.
Signature
1 | function renderToSimpleStream( |
Usage
1 | let res = '' |