简体   繁体   English

Vue.js:将新的Vue()。$ mount()转换为导出以进行服务器端渲染

[英]Vue.js: converting a new Vue().$mount() to an export for server side rendering

I have a Vue app that I'm trying to convert to server-side rendering. 我有一个Vue应用,正在尝试将其转换为服务器端渲染。

Currently, the app attaches to the root HTML element through this file: 目前,该应用通过此文件附加到根HTML元素:

import Vue from 'vue';
import AppLayout from './theme/Layout.vue';
import router from '../router';
import store from './vuex/index';

Vue.config.productionTip = false;

new Vue({
    router,
    ...AppLayout,
    store
}).$mount('#app');

I would like to export this root file for my server-entry.js file. 我想将此根文件导出为我的server-entry.js文件。

What's the most efficient way to do this? 最有效的方法是什么? Should I refactor the main.js file? 我应该重构main.js文件吗? Should I create a separate file, the only purpose of which would be to pull in all the imports listed above and export an app, then import it and mount it in main.js ? 我是否应该创建一个单独的文件,其唯一目的是提取上面列出的所有导入文件并导出应用程序,然后将其导入并将其安装在main.js中 What would that look like? 那会是什么样?

Here is what I have right now, which works: 这是我现在所拥有的,可以正常工作:

app.js: app.js:

import Vue from 'vue';
import AppLayout from './theme/Layout.vue';
import router from '../router';
import store from './vuex/index';

Vue.config.productionTip = false;

const app = new Vue ({
    router,
    ...AppLayout,
    store
});

export {app, router, store};

main.js: main.js:

import {app} from './app';

app.$mount('#app');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM