<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="https://unpkg.com/vue@next"></script>
</head>
<body>
<div id="root"></div>
<script>
const HelloWorld = {
data() {
return {
count: 0
}
},
template: '<div>{{count}} <button @click="count+=1">增加</button></div>'
}
const app = Vue.createApp({
components: { HelloWorld }, // 局部组件注册 建议大写字母开头、驼峰命名
template: `<div>
<demo class="red" name='1'/>
<hello-world />
</div>`,
data(){
return {
msg: 'hello world',
}
},
methods: {
},
})
// 全局组件
app.component('demo', {
template: `<div >hello world</div>`
})
app.mount('#root')
</script>
</body>
</html>
vue3基础入门二-组件注册
于 2022-02-03 18:23:44 首次发布