Skip to content

Commit ab32263

Browse files
committed
feat: vuejs#181 Change scope of ref with v-scope
1 parent 9a285a2 commit ab32263

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/directives/if.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export const _if = (el: Element, exp: string, ctx: Context) => {
6161
if (i !== activeBranchIndex) {
6262
removeActiveBlock();
6363
block = new Block(el, ctx);
64-
block.insert(parent, anchor);
64+
block.insert(parent as any, anchor);
6565
parent.removeChild(anchor);
6666
activeBranchIndex = i;
6767
}

src/walk.ts

+5
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const modifierRE = /\.([\w-]+)/g
1515
export let inOnce = false
1616

1717
export const walk = (node: Node, ctx: Context): ChildNode | null | void => {
18+
const parentCtx = ctx
1819
const type = node.nodeType
1920
if (type === 1) {
2021
// Element
@@ -40,6 +41,7 @@ export const walk = (node: Node, ctx: Context): ChildNode | null | void => {
4041
// v-scope
4142
if ((exp = checkAttr(el, 'v-scope')) || exp === '') {
4243
const scope = exp ? evaluate(ctx.scope, exp) : {}
44+
scope.$root = el;
4345
ctx = createScopedContext(ctx, scope)
4446
if (scope.$template) {
4547
resolveTemplate(el, scope.$template)
@@ -54,6 +56,9 @@ export const walk = (node: Node, ctx: Context): ChildNode | null | void => {
5456

5557
// ref
5658
if ((exp = checkAttr(el, 'ref'))) {
59+
if (ctx !== parentCtx) {
60+
applyDirective(el, ref, `"${exp}"`, parentCtx)
61+
}
5762
applyDirective(el, ref, `"${exp}"`, ctx)
5863
}
5964

0 commit comments

Comments
 (0)