Skip to content

Commit f2662b5

Browse files
committed
Add web components initial support
1 parent 579cd71 commit f2662b5

File tree

6 files changed

+27
-19
lines changed

6 files changed

+27
-19
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## [1.0.3](https://github.com/ws-rush/power-vue/compare/v0.4.1...v1.0.3) (2023-02-23)
2+
3+
4+
15
## [1.0.2](https://github.com/ws-rush/power-vue/compare/v0.4.1...v1.0.2) (2023-02-23)
26

37

examples/components.html

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,17 @@
11
<script type="module">
2-
import { createApp } from '../src'
2+
import { define } from '../src'
33

44

55
// Custom Elements
6-
export class MyCounter extends HTMLElement {
7-
data() {
8-
return {
9-
$template: `<template>My count is {{ count }}<button @click="inc">++</button></template>`,
10-
count: 0,
11-
inc() {
12-
this.count++
13-
}
6+
define('my-counter', () => {
7+
return {
8+
$template: `<template>My count is {{ count }}<button @click="inc">++</button></template>`,
9+
count: 0,
10+
inc() {
11+
this.count++
1412
}
1513
}
16-
17-
connectedCallback() {
18-
this.setAttribute('v-scope', "$el.data()")
19-
createApp().mount(this)
20-
}
21-
}
22-
23-
customElements.define("my-counter", MyCounter)
14+
})
2415
</script>
2516

2617
<my-counter count="hello"></my-counter>

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "power-vue",
3-
"version": "1.0.3",
3+
"version": "1.0.4",
44
"description": "petite-vue fork with plugins support",
55
"main": "dist/power-vue.umd.js",
66
"unpkg": "dist/power-vue.iife.js",

src/define.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { createApp } from "./app"
2+
3+
export function define(name: string, data: Function) {
4+
customElements.define(name, class extends HTMLElement {
5+
data = data
6+
7+
connectedCallback() {
8+
this.setAttribute('v-scope', "$el.data()")
9+
createApp().mount(this)
10+
}
11+
})
12+
}

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
export { define } from './define'
12
export { createApp } from './app'
23
export { nextTick } from './scheduler'
34
export { reactive } from '@vue/reactivity'

vite.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export default defineConfig({
1010
minify: 'terser',
1111
lib: {
1212
entry: resolve(__dirname, 'src/index.ts'),
13-
name: 'PetiteVue',
13+
name: 'PowerVue',
1414
formats: ['es', 'umd', 'iife']
1515
},
1616
rollupOptions: {

0 commit comments

Comments
 (0)