vue3 全局组件/局部组件
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>vue3组件</title><scri
·
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>vue3组件</title>
<script src="./vue3.js"></script>
</head>
<body>
<div id="app">
{{msg}}
<br>
----------
<br>
全局组件:<child></child>
<br>
局部组件:<comp></comp>
</div>
<template id="comp">
子组件内容 {{msg}} {{count}}
<button @click="count++">add</button>
</template>
<script>
const {createApp} = Vue
const comp = {
data:()=>({
msg:'子组件',
count:0
}),
template:"#comp",
methods:{ }
}
const options = {
data:()=>({
msg:'vue3组件'
}),
components:{
comp
}
}
const app = createApp(options)
// 创建一个全局组件
app.component('child',comp)
app.mount('#app')
</script>
</body>
</html>
更多推荐
已为社区贡献4条内容
所有评论(0)