Skip to content

Commit 43c8cec

Browse files
author
jack
committed
构建web-component
1 parent 3381401 commit 43c8cec

File tree

4 files changed

+48
-4
lines changed

4 files changed

+48
-4
lines changed

package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
{
22
"name": "hello-vue",
33
"version": "0.1.0",
4-
"private": true,
4+
"private": false,
5+
"files": [
6+
"dist",
7+
"package.json"
8+
],
9+
"unpkg":"dist/ng-bi.min.js",
510
"scripts": {
611
"serve": "vue-cli-service serve",
712
"build": "vue-cli-service build",
813
"lint": "vue-cli-service lint",
9-
"wc": "vue-cli-service build --target wc --name ng-bi './src/views/web-component/components/*.vue'"
14+
"wc": "vue-cli-service build --target wc --name ng-bi './src/components/*.vue'"
1015
},
1116
"dependencies": {
1217
"core-js": "^3.6.4",

src/components/HelloWorld.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88
export default {
99
name: 'HelloWorld',
1010
props: {
11-
msg: String
11+
msg: {
12+
type: String,
13+
default: 'Hello World!'
14+
}
1215
},
1316
data() {
1417
return {}

src/views/Home.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<div>
3-
<HelloWorld msg="Welcome to Your Vue.js App" />
3+
<HelloWorld />
44
<MyVueName />
55
<MyRating />
66
</div>

test.html

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<!--
2+
* @Description :
3+
* @Date : 2022-01-17 00:09:08 +0800
4+
* @Author : JackChou
5+
* @LastEditTime: 2022-01-17 00:22:54 +0800
6+
* @LastEditors : JackChou
7+
-->
8+
<!DOCTYPE html>
9+
<html lang="en">
10+
11+
<head>
12+
<meta charset="UTF-8">
13+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
14+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
15+
<title>Document</title>
16+
<script src="https://unpkg.com/vue"></script>
17+
<script type="module" src="https://unpkg.com/web-components-jack"></script>
18+
<script src="/dist/ng-bi.min.js"></script>
19+
<script>
20+
// NOTE 告诉 vue 哪些时自定义元素
21+
Vue.config.ignoredElements = ['my-rating', 'my-name']
22+
document.addEventListener("DOMContentLoaded", () => {
23+
const myRating = document.querySelector('ng-bi-my-rating')
24+
myRating.buttonOptions = { size: 'mini', round: true }
25+
})
26+
</script>
27+
</head>
28+
29+
<body>
30+
<ng-bi-hello-world msg="从 vue component 到 web-component"></ng-bi-hello-world>
31+
<ng-bi-hello-world></ng-bi-hello-world>
32+
<ng-bi-my-name></ng-bi-my-name>
33+
<ng-bi-my-rating></ng-bi-my-rating>
34+
</body>
35+
36+
</html>

0 commit comments

Comments
 (0)