Skip to content

Commit

Permalink
feat: vuejs#181 Change scope of ref with v-scope
Browse files Browse the repository at this point in the history
  • Loading branch information
thewei committed Nov 9, 2023
1 parent 9a285a2 commit ab32263
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/directives/if.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export const _if = (el: Element, exp: string, ctx: Context) => {
if (i !== activeBranchIndex) {
removeActiveBlock();
block = new Block(el, ctx);
block.insert(parent, anchor);
block.insert(parent as any, anchor);
parent.removeChild(anchor);
activeBranchIndex = i;
}
Expand Down
5 changes: 5 additions & 0 deletions src/walk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const modifierRE = /\.([\w-]+)/g
export let inOnce = false

export const walk = (node: Node, ctx: Context): ChildNode | null | void => {
const parentCtx = ctx
const type = node.nodeType
if (type === 1) {
// Element
Expand All @@ -40,6 +41,7 @@ export const walk = (node: Node, ctx: Context): ChildNode | null | void => {
// v-scope
if ((exp = checkAttr(el, 'v-scope')) || exp === '') {
const scope = exp ? evaluate(ctx.scope, exp) : {}
scope.$root = el;
ctx = createScopedContext(ctx, scope)
if (scope.$template) {
resolveTemplate(el, scope.$template)
Expand All @@ -54,6 +56,9 @@ export const walk = (node: Node, ctx: Context): ChildNode | null | void => {

// ref
if ((exp = checkAttr(el, 'ref'))) {
if (ctx !== parentCtx) {
applyDirective(el, ref, `"${exp}"`, parentCtx)
}
applyDirective(el, ref, `"${exp}"`, ctx)
}

Expand Down

0 comments on commit ab32263

Please sign in to comment.