vuejs-challenges icon indicating copy to clipboard operation
vuejs-challenges copied to clipboard

22 - 自定义元素

Open kalu5 opened this issue 2 years ago • 0 comments

// 你的答案
<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>

kalu5 avatar Sep 19 '22 03:09 kalu5