vuejs-challenges
vuejs-challenges copied to clipboard
22 - 自定义元素
// 你的答案
<script setup lang='ts'>
import { onMounted, defineCustomElement, render, h } from "vue"
/**
* Implement the code to create a custom element.
* Make the output of page show "Hello Vue.js".
*/
const VueJs = defineCustomElement({
props: {
message: {
type: String,
default: ''
}
},
render() {
return h(
'h1',
null,
this.message
)
}
})
customElements.define('vue-js', VueJs)
onMounted(() => {
document.getElementById("app")!.innerHTML = "<vue-js message=\"Hello Vue.js\"></vue-js>"
})
</script>
<template>
<div id="app"></div>
</template>