1 Star 0 Fork 0

Eugene/mini-vue2

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
component.html 947 Bytes
一键复制 编辑 原始数据 按行查看 历史
egu0 提交于 2024-05-09 00:33 +08:00 . 12.2.创建自定义组件的虚拟 dom
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div id="app">
<my-button></my-button>
<my-button></my-button>
{{msg}}
<my-button></my-button>
</div>
</body>
<script src="dist/vue.js"></script>
<script>
//通过 Vue.component 全局注册组件
Vue.component('my-button', {
template: `<button>我的全局按钮</button>`
})
let vm = new Vue({
el: "#app",
data() {
return {
msg: 'monica',
}
},
//在 options.components 字段局部注册组件。优先级比同名全局组件高
components: {
'my-button': {
template: `<button>我的局部按钮</button>`
}
}
})
console.log('vm', vm)
</script>
</html>
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/egu0/mini-vue2.git
git@gitee.com:egu0/mini-vue2.git
egu0
mini-vue2
mini-vue2
master

搜索帮助