Skip to content

Commit f05da67

Browse files
author
wusaby-rush
committed
Revert "Add $root refer to component root element"
This reverts commit db587d8.
1 parent db587d8 commit f05da67

File tree

3 files changed

+2
-13
lines changed

3 files changed

+2
-13
lines changed

README.md

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,6 @@
2727
{{ count }}
2828
<button @click="count++">inc</button>
2929
</div>
30-
31-
<!-- another example -->
32-
<textarea
33-
v-scope="{width: $root.offsetWidth, height: $root.offsetHeight}"
34-
@click="width = $el.offsetWidth; height = $el.offsetHeight;"
35-
>
36-
{{ width }} &times; {{ height }}
37-
</textarea>
3830
```
3931

4032
- Use `v-scope` to mark regions on the page that should be controlled by `petite-vue`.
@@ -354,11 +346,10 @@ Check out the [examples directory](https://github.com/vuejs/petite-vue/tree/main
354346
- `v-scope`
355347
- `v-effect`
356348
- `@vue:mounted` & `@vue:unmounted` events
357-
- `$root` refer to component root element
358349

359350
### Has Different Behavior
360351

361-
- In expressions, `$el` points to the current element the directive is bound to (instead of component root element which accessed by `$root`)
352+
- In expressions, `$el` points to the current element the directive is bound to (instead of component root element)
362353
- `createApp()` accepts global state instead of a component
363354
- Components are simplified into object-returning functions
364355
- Custom directives have a different interface

src/walk.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ export const walk = (node: Node, ctx: Context): ChildNode | null | void => {
4040
// v-scope
4141
if ((exp = checkAttr(el, 'v-scope')) || exp === '') {
4242
const scope = exp ? evaluate(ctx.scope, exp) : {}
43-
scope.$root = el
4443
ctx = createScopedContext(ctx, scope)
4544
if (scope.$template) {
4645
resolveTemplate(el, scope.$template)

tests/ref.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
v-scope="{ dynamicRef: 'x', show: true }"
1010
v-effect="console.log({ x: $refs.x, y: $refs.y, input: $refs.input })"
1111
>
12-
<p>Accessing root el (with ref): id is {{ $refs.root.id }}</p>
13-
<p>Accessing root el (with $root): id is {{ $refs.root.id }}</p>
12+
<p>Accessing root el: id is {{ $refs.root.id }}</p>
1413

1514
<input ref="input" />
1615
<span v-if="show" :ref="dynamicRef">Span with dynamic ref</span>

0 commit comments

Comments
 (0)