Skip to content

Commit b2c8242

Browse files
committed
fix(cli): fixed parent scope
1 parent 6c47f28 commit b2c8242

File tree

4 files changed

+35
-19
lines changed

4 files changed

+35
-19
lines changed

packages/cli/core/plugins/template/directives/for.js

+19-17
Original file line numberDiff line numberDiff line change
@@ -4,47 +4,49 @@ const stripParensRE = /^\(|\)$/g;
44
const variableRE = /^\s*[a-zA-Z\$_][a-zA-Z\d_]*\s*$/;
55

66
exports = module.exports = function () {
7-
8-
this.register('template-parse-ast-attr-v-for', function parseDirectivesFor ({item, name, expr, parentScope}) {
7+
8+
this.register('template-parse-ast-attr-v-for', function parseDirectivesFor ({item, name, expr, scope}) {
99
let res = {};
10-
let scope = {};
10+
let currentScope = {};
1111
let inMatch = expr.match(forAliasRE);
1212
let variableMatch = expr.match(variableRE);
1313
if (variableMatch) {
1414
// e.g: v-for="items"
1515
res.alias = 'item';
1616
res.for = variableMatch[0].trim();
17-
scope.for = res.for;
18-
scope.declared = [];
17+
currentScope.for = res.for;
18+
currentScope.declared = [];
1919
}
2020

2121
if (inMatch) {
22-
scope.declared = scope.declared || [];
22+
currentScope.declared = currentScope.declared || [];
2323
res.for = inMatch[2].trim();
24+
currentScope.for = res.for;
2425
let alias = inMatch[1].trim().replace(stripParensRE, '');
2526
let iteratorMatch = alias.match(forIteratorRE);
2627
if (iteratorMatch) {
2728
res.alias = alias.replace(forIteratorRE, '').trim();
28-
scope.declared.push(res.alias);
29-
scope.alias = res.alias;
29+
currentScope.declared.push(res.alias);
30+
currentScope.alias = res.alias;
3031
res.iterator1 = iteratorMatch[1].trim();
31-
scope.iterator1 = res.iterator1;
32-
scope.declared.push(res.iterator1);
32+
currentScope.iterator1 = res.iterator1;
33+
currentScope.declared.push(res.iterator1);
3334
if (iteratorMatch[2]) {
3435
res.iterator2 = iteratorMatch[2].trim();
35-
scope.iterator2 = res.iterator2;
36-
scope.declared.push(res.iterator2);
36+
currentScope.iterator2 = res.iterator2;
37+
currentScope.declared.push(res.iterator2);
3738
}
3839
} else {
3940
res.alias = alias;
40-
scope.alias = alias;
41-
scope.declared.push(alias);
41+
currentScope.alias = alias;
42+
currentScope.declared.push(alias);
4243
}
4344
}
44-
if (parentScope)
45-
scope.parent = parentScope;
45+
if (scope) {
46+
currentScope.parent = scope;
47+
}
4648
return {
47-
scope: scope,
49+
scope: currentScope,
4850
attrs: {
4951
'wx:for': `{{ ${res.for} }}`,
5052
'wx:for-index': `${res.iterator1 || 'index'}`,

packages/core/dist/wepy.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,14 @@ function set (vm, target, key, val) {
759759
target.splice(key, 1, val);
760760
return val
761761
}
762+
var ref = getRootAndPath(key, target);
763+
var root = ref.root;
764+
var path = ref.path;
765+
766+
// push parent key to dirty, wait to setData
767+
vm.$dirty.push(root, path, val);
768+
769+
762770
if (key in target && !(key in Object.prototype)) {
763771
target[key] = val;
764772
return val
@@ -1666,7 +1674,7 @@ var proxyHandler = function (e) {
16661674

16671675
if (model) {
16681676
if (type === model.type) {
1669-
if (isFunc(mode.handler)) {
1677+
if (isFunc(model.handler)) {
16701678
model.handler.call(vm, e.detail.value, modelParams);
16711679
}
16721680
}

packages/core/weapp/init/methods.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ const proxyHandler = function (e) {
6161

6262
if (model) {
6363
if (type === model.type) {
64-
if (isFunc(mode.handler)) {
64+
if (isFunc(model.handler)) {
6565
model.handler.call(vm, e.detail.value, modelParams);
6666
}
6767
}

packages/core/weapp/observer/index.js

+6
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,12 @@ export function set (vm, target, key, val) {
218218
target.splice(key, 1, val)
219219
return val
220220
}
221+
let {root, path} = getRootAndPath(key, target);
222+
223+
// push parent key to dirty, wait to setData
224+
vm.$dirty.push(root, path, val);
225+
226+
221227
if (key in target && !(key in Object.prototype)) {
222228
target[key] = val
223229
return val

0 commit comments

Comments
 (0)