vue#createSSRApp JavaScript Examples
The following examples show how to use
vue#createSSRApp.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: main.js From u-draw-poster with MIT License | 5 votes |
export function createApp() {
const app = createSSRApp(App)
return {
app
}
}
Example #2
Source File: main.js From F6 with MIT License | 5 votes |
export function createApp() {
const app = createSSRApp(App);
return {
app,
};
}
Example #3
Source File: entry-server.js From vue3-ts-vite-ssr-starter with MIT License | 5 votes |
export async function render(url, manifest) {
const router = createRouter();
const store = createPinia();
const app = createSSRApp(App);
app.use(router).use(store);
router.push(url);
try {
await router.isReady();
const to = router.currentRoute;
const matchedRoute = to.value.matched;
if (to.value.matched.length === 0) {
return '';
}
const matchedComponents = [];
matchedRoute.map((route) => {
matchedComponents.push(...Object.values(route.components));
});
const asyncDataFuncs = matchedComponents.map((component) => {
const asyncData = component.asyncData || null;
if (asyncData) {
const config = {
store,
route: to
};
if (isPromise(asyncData) === false) {
const result = asyncData(config);
return Promise.resolve(result);
}
return asyncData(config);
}
});
await Promise.all(asyncDataFuncs);
const ctx = {};
const html = await renderToString(app, ctx);
const preloadLinks = renderPreloadLinks(ctx.modules, manifest);
const state = JSON.stringify(store.state.value);
return [html, state, preloadLinks];
} catch (error) {
console.log(error);
}
}