master
Evan Chen 2022-07-18 11:10:42 +08:00
parent f1698b4cb2
commit 6b63b9f8c6
3 changed files with 14 additions and 13 deletions

View File

@ -9,11 +9,11 @@
content="Web site created using create-react-app"
/>
<title>React App</title>
<link rel="stylesheet" href="dist/index.css">
<link rel="stylesheet" href="index.css">
</head>
<body>
<wc-test id='test' name='Evan'></wc-test>
</body>
<script src="dist/index.js"></script>
<script src="index.js" type="module"></script>
</html>

View File

@ -26,12 +26,8 @@ WcTestApp.defaultProps = {
class WcTest extends HTMLElement {
root;
// declare attributes we want to keep track of
static get observedAttributes() {
return ['name', 'onclick'];
}
connectedCallback() {
constructor(){
super()
let mountPoint = this;
// ShadowRoot (global styles will not apply, but safer with a complete isolation layer)
@ -41,14 +37,19 @@ class WcTest extends HTMLElement {
this.render()
}
render(){
// declare attributes we want to keep track of
static get observedAttributes() {
return ['name', 'onclick'];
}
// connectedCallback() {
// }
render(){
const name = this.hasAttribute('name')
? this.getAttribute('name')
: undefined;
console.log(this.root)
this.root.render(<WcTestApp name={name} />);
}

View File

@ -10,8 +10,8 @@
"react-dom": "^18.2.0"
},
"scripts": {
"start": "yarn parcel index.js index.css",
"build": "yarn parcel build index.js index.css"
"start": "yarn parcel index.html",
"build": "(rm -rf dist||true) && yarn parcel build index.html"
},
"browserslist": {
"production": [