Skip to content

Latest commit

 

History

History
94 lines (69 loc) · 2.55 KB

README.md

File metadata and controls

94 lines (69 loc) · 2.55 KB

egg-view-vue-ssr

NPM version build status Test coverage David deps Known Vulnerabilities npm download

vue server side render solution for egg-view-vue

Install

$ npm i egg-view-vue-ssr --save

Usage

// {app_root}/config/plugin.js
exports.vuessr = {
  enable: true,
  package: 'egg-view-vue-ssr',
};

Configuration

// {app_root}/config/config.default.js
exports.vuessr = {
 // layout: path.join(app.baseDir, 'app/view/layout.html'),
 // manifest: path.join(app.baseDir, 'config/manifest.json'),
 // buildConfig: path.join(app.baseDir, 'config/buildConfig.json'),
 // injectCss: true,
 // injectJs: true,
 // injectRes: []
 // fallbackToClient: true, // fallback to client rendering after server rendering failed
 // afterRender: (html, context) => {
 //      return html;
 // },
};

Render

Server Render, call render method

// controller/home.js
exports.index = function* (ctx) {
  yield ctx.render('index/index.js', Model.getPage(1, 10));
};

Client Render, Call renderClient or build static html to egg-static dir by Webpack.

when client render , the template is exports.vuessr.layout

// controller/home.js
exports.client = function* (ctx) {
  yield ctx.renderClient('index/index.js', Model.getPage(1, 10));
};

see config/config.default.js for more detail.

Questions & Suggestions

Please open an issue here.

License

MIT