Skip to content

Commit

Permalink
fix: renderClient set options.layout
Browse files Browse the repository at this point in the history
  • Loading branch information
hubcarl committed Sep 6, 2018
1 parent 0bb0ad5 commit fd0b4cf
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
24 changes: 21 additions & 3 deletions lib/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Engine {
this.vueServerRenderer = vueServerRenderer;
this.renderer = this.vueServerRenderer.createRenderer();
this.renderOptions = this.config.renderOptions;

this.fileCache = [];
if (this.config.cache === true) {
this.bundleCache = LRU({
max: 1000,
Expand Down Expand Up @@ -43,6 +43,19 @@ class Engine {
return this[VUE_RESOURCE];
}

getTemplate(options = {}) {
const filepath = options.layout;
if (filepath) {
if (this.fileCache[filepath]) {
return this.fileCache[filepath];
}
const content = fs.readFileSync(filepath, 'utf8');
this.fileCache[filepath] = content;
return content;
}
return options.renderOptions && options.renderOptions.template || this.template;
}

normalizeLocals(ctx, locals = {}, options = {}, engine = true) {
// egg-view engine mode, the locals had merged
if (engine) {
Expand Down Expand Up @@ -117,9 +130,14 @@ class Engine {
});
}

renderClient(name, locals, options) {
renderClient(name, locals, options = {}) {
const template = this.getTemplate(options);
// 不进行Vue layout数据绑定编译
if (options.viewEngine === null) {
const html = this.resource ? this.resource.inject(template, name, locals, options) : template;
return Promise.resolve(html);
}
options.viewEngine = 'vue';
const template = options.renderOptions && options.renderOptions.template || this.template;
return this.renderString(template, locals, options).then(html => {
return this.resource ? this.resource.inject(html, name, locals, options) : html;
});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "egg-view-vue-ssr",
"version": "3.1.2",
"version": "3.1.3",
"description": "vue server side render solution for egg",
"eggPlugin": {
"name": "vuessr"
Expand Down

0 comments on commit fd0b4cf

Please sign in to comment.