vue 简单实验 自定义组件 component
1.代码
<script src="https://unpkg.com/vue@next" rel="external nofollow" ></script>
<div id="components-demo"><button-counter></button-counter>
</div>
<script>
// 创建一个Vue 应用
const app = Vue.createApp({})
// 定义一个名为 button-counter 的新全局组件
app.component('button-counter', {data() {return {count: 0}},template: `<button @click="count++">You clicked me {{ count }} times.</button>`
})
// 绑定一个新的组件,新的组件中使用前面创建的组件
app.mount('#components-demo')
</script>
2.运行