Skip to content

Commit

Permalink
fix: render client locals merge
Browse files Browse the repository at this point in the history
  • Loading branch information
hubcarl committed Jul 20, 2018
1 parent 9b10f2e commit 406316a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion app/extend/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module.exports = {
return this.renderVueClient(name, locals, options);
},
renderVueClient(name, locals, options = {}) {
locals = this.app.vue.normalizeLocals(this, locals);
locals = this.app.vue.normalizeLocals(this, locals, options, false);
return this.app.vue.renderClient(name, locals, options).then(html => {
this.body = html;
});
Expand Down
22 changes: 16 additions & 6 deletions lib/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,26 @@ class Engine {
return this[VUE_RESOURCE];
}

normalizeLocals(ctx, locals = {}, options = {}) {
normalizeLocals(ctx, locals = {}, options = {}, engine = true) {
// egg-view engine mode, the locals had merged
if (engine) {
if (this.config.mergeLocals) {
return this.setCSRFLocals(ctx, locals);
}
}
// source locals, no merge locals
const sourceLocals = options && options.locals ? options.locals : locals;
// default locals and data merge;
if (this.config.mergeLocals) {
[ 'ctx', 'request', 'helper' ].forEach(key => {
Object.defineProperty(locals, key, { enumerable: false });
});
return this.setCSRFLocals(ctx, locals);
locals = Object.assign({}, { ctx, request: ctx.request, helper: ctx.helper }, ctx.locals, sourceLocals);
} else {
locals = Object.assign({}, { ctx, request: ctx.request, helper: ctx.helper }, sourceLocals);
}
[ 'ctx', 'request', 'helper' ].forEach(key => {
Object.defineProperty(locals, key, { enumerable: false });
});
// only data
return this.setCSRFLocals(ctx, options && options.locals || {});
return this.setCSRFLocals(ctx, locals);
}

setCSRFLocals(ctx, locals) {
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.0",
"version": "3.1.1",
"description": "vue server side render solution for egg",
"eggPlugin": {
"name": "vuessr"
Expand Down

0 comments on commit 406316a

Please sign in to comment.