import { createApp } from './main' export default context => { return new Promise((resolve, reject) => { const beginTime = Date.now() const { app, router, store } = createApp(context) // set router's location router.push(context.url) router.onReady(() => { // This `rendered` hook is called when the app has finished rendering context.rendered = () => { // After the app is rendered, our store is now // filled with the state from our components. // When we attach the state to the context, and the `template` option // is used for the renderer, the state will automatically be // serialized and injected into the HTML as `window.__INITIAL_STATE__`. context.state = store.state //必须 } resolve(app) }, reject) }) }
entry-client.ts
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
import { createApp } from './main' const { app, router, store } = createApp() //必须 if (window.__INITIAL_STATE__) { store.replaceState(window.__INITIAL_STATE__) } router.onReady(() => { app.$mount('#app') })