<!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>
</head>
<body>
<div id="app">
<counter></counter>
<button-counter></button-counter>
</div>
<script src="/../node_modules/vue/dist/vue.js"></script>
<script>
//全局声明一个组件
Vue.component("counter",{
template:`<button v-on:click="count++">我被点击了{{count}}次</button>`,
data(){
return{
count:1
}
}
});
//局部声明一个组件
const buttonCounter={
template:`<button v-on:click="count++">我被点击了{{count}}次!!!</button>`,
data(){
return{
count:1
}
}
};
new Vue({
el:"#app",
data:{
count:1
},
components:{
'button-counter':buttonCounter
}
})
</script>
</body>
</html>
Vue组件化实例代码
最新推荐文章于 2024-04-11 18:04:43 发布