Skip to content

Commit 3b3a1bb

Browse files
committed
Expose $el to v-scope
1 parent 765ad2c commit 3b3a1bb

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

examples/components.html

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<script type="module">
2+
import { createApp } from '../src'
3+
4+
export class MyCounter extends HTMLElement {
5+
data() {
6+
return {
7+
count: 0,
8+
}
9+
}
10+
11+
connectedCallback() {
12+
this.setAttribute('v-scope', "$el.data()")
13+
this.innerHTML = `
14+
<style>
15+
* {
16+
font-size: 100%;
17+
}
18+
19+
span {
20+
width: 4rem;
21+
display: inline-block;
22+
text-align: center;
23+
}
24+
25+
button {
26+
width: 4rem;
27+
height: 4rem;
28+
border: none;
29+
border-radius: 10px;
30+
background-color: seagreen;
31+
color: white;
32+
}
33+
</style>
34+
<button @click="count--">-</button>
35+
<span v-text="count"></span>
36+
<button @click="count++">+</button>
37+
`
38+
}
39+
}
40+
41+
customElements.define("my-counter", MyCounter)
42+
createApp().mount()
43+
</script>
44+
45+
<my-counter />

src/walk.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export const walk = (node: Node, ctx: Context): ChildNode | null | void => {
4040

4141
// v-scope
4242
if ((exp = checkAttr(el, 'v-scope')) || exp === '') {
43-
const scope = exp ? evaluate(ctx.scope, exp) : {}
43+
const scope = exp ? evaluate(ctx.scope, exp, el) : {}
4444
scope.$root = el
4545
ctx = createScopedContext(ctx, scope)
4646
if (scope.$template) {

0 commit comments

Comments
 (0)