Skip to content

Commit

Permalink
Support <template> in
Browse files Browse the repository at this point in the history
  • Loading branch information
rush committed Feb 23, 2023
1 parent f66176f commit 579cd71
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 28 deletions.
35 changes: 8 additions & 27 deletions examples/components.html
Original file line number Diff line number Diff line change
@@ -1,45 +1,26 @@
<script type="module">
import { createApp } from '../src'


// Custom Elements
export class MyCounter extends HTMLElement {
data() {
return {
$template: `<template>My count is {{ count }}<button @click="inc">++</button></template>`,
count: 0,
inc() {
this.count++
}
}
}

connectedCallback() {
this.setAttribute('v-scope', "$el.data()")
this.innerHTML = `
<style>
* {
font-size: 100%;
}
span {
width: 4rem;
display: inline-block;
text-align: center;
}
button {
width: 4rem;
height: 4rem;
border: none;
border-radius: 10px;
background-color: seagreen;
color: white;
}
</style>
<button @click="count--">-</button>
<span v-text="count"></span>
<button @click="count++">+</button>
`
createApp().mount(this)
}
}

customElements.define("my-counter", MyCounter)
createApp().mount()
</script>

<my-counter />
<my-counter count="hello"></my-counter>
2 changes: 1 addition & 1 deletion src/walk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,5 +188,5 @@ const resolveTemplate = (el: Element, template: string) => {
el.appendChild((templateEl as HTMLTemplateElement).content.cloneNode(true))
return
}
el.innerHTML = template
el.innerHTML = template.replace(/<[\/\s]*template\s*>/ig, '')
}

0 comments on commit 579cd71

Please sign in to comment.