File tree Expand file tree Collapse file tree 6 files changed +25
-22
lines changed Expand file tree Collapse file tree 6 files changed +25
-22
lines changed Original file line number Diff line number Diff line change @@ -7,15 +7,17 @@ import VueRouter from 'vue-router';
7
7
import store from './vuex' ;
8
8
import App from './app.vue' ;
9
9
10
- import router from './router/index' ;
10
+ import { createRouter } from './router/index' ;
11
11
12
12
Vue . use ( VueRouter ) ;
13
13
Vue . use ( Carousel3d ) ;
14
14
15
- const app = new Vue ( {
16
- router,
17
- store,
18
- render : h => h ( App )
19
- } ) ;
20
-
21
- export { app , router , store } ;
15
+ export const createApp = ( ) => {
16
+ const router = createRouter ( ) ;
17
+ const app = new Vue ( {
18
+ router,
19
+ store,
20
+ render : h => h ( App )
21
+ } ) ;
22
+ return { app, router, store } ;
23
+ }
Original file line number Diff line number Diff line change 1
1
/**
2
2
* Created by zhaofeng on 2016/12/2.
3
3
*/
4
- import { WOW } from 'wowjs' ;
4
+ import { WOW } from 'wowjs' ;
5
5
import LazyLoad from 'vanilla-lazyload' ;
6
6
import "jquery" ;
7
+ import { createApp } from './app' ;
7
8
8
- import { app , store } from './app'
9
+ const { app, store } = createApp ( ) ;
9
10
10
11
//将服务端渲染时候的状态写入vuex
11
12
if ( window . __INITIAL_STATE__ ) {
@@ -17,4 +18,4 @@ app.$mount('#app');
17
18
18
19
new WOW ( ) . init ( ) ;
19
20
20
- window . lazyload = new LazyLoad ( ) ;
21
+ window . lazyload = new LazyLoad ( ) ;
Original file line number Diff line number Diff line change 2
2
* Created by zhaofeng on 2016/12/2.
3
3
*/
4
4
import VueRouter from 'vue-router' ;
5
-
6
5
import * as HomePage from '../page/home.vue' ;
7
6
8
7
/**
9
8
* Vue Router
10
9
*/
11
- export default new VueRouter ( {
10
+ export const createRouter = ( ) => new VueRouter ( {
12
11
// mode: 'history',
13
12
routes : [
14
13
{ path : '/' , component : HomePage }
15
14
]
16
- } ) ;
15
+ } ) ;
Original file line number Diff line number Diff line change
1
+ import { createApp } from "./app" ;
2
+
1
3
/**
2
4
* Created by zhaofeng on 2016/12/2.
3
5
*/
4
- import { app , router , store } from './app' ;
5
-
6
6
const isDev = process . env . NODE_ENV !== 'production' ;
7
7
8
8
export default function ( context ) {
9
9
const s = isDev && Date . now ( ) ;
10
10
11
+ const { app, router, store } = createApp ( ) ;
11
12
// set router's location
12
13
router . push ( context . url ) ;
13
14
const matchedComponents = router . getMatchedComponents ( ) ;
14
15
15
16
// no matched routes
16
17
if ( ! matchedComponents . length ) {
17
- return Promise . reject ( { code : '404' } ) ;
18
+ return Promise . reject ( { code : '404' } ) ;
18
19
}
19
20
20
21
// Call preFetch hooks on components matched by the route.
@@ -36,4 +37,4 @@ export default function (context) {
36
37
context . initialState = store . state ;
37
38
return app
38
39
} )
39
- }
40
+ }
Original file line number Diff line number Diff line change @@ -32,4 +32,4 @@ export default class HomeController extends BaseController {
32
32
keyword : keyword
33
33
} ) ;
34
34
}
35
- }
35
+ }
Original file line number Diff line number Diff line change @@ -14,15 +14,15 @@ export function init(app) {
14
14
if ( process . env . NODE_ENV === 'production' ) {
15
15
//如果是生产环境,bundle是构建完成的正式文件
16
16
const bundlePath = path . resolve ( __dirname , '../../../dist/server-bundle.js' ) ;
17
- renderer = createBundleRenderer ( fs . readFileSync ( bundlePath , 'utf-8' ) )
17
+ renderer = createBundleRenderer ( fs . readFileSync ( bundlePath , 'utf-8' ) , { runInNewContext : 'once' } )
18
18
} else {
19
19
//如果是开发环境,bundle会在改变之后重新回调生成
20
20
require ( '../../../build/setup-dev-server' ) ( app , bundle => {
21
- renderer = createBundleRenderer ( bundle )
21
+ renderer = createBundleRenderer ( bundle , { runInNewContext : 'once' } )
22
22
} )
23
23
}
24
24
}
25
25
26
26
export function getRenderer ( ) {
27
27
return renderer ;
28
- }
28
+ }
You can’t perform that action at this time.
0 commit comments