谷粒商城day27 -Vue-组件化

tech2022-08-14  141

全局组件与局部组件

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <script src="../node_modules/vue/dist/vue.js"></script> </head> <body > <div id = "app"> <h1>{{name}} 你好啊!</h1> <buttonadd></buttonadd> </br> <but_add></but_add> </div> <script> //全局组件 Vue.component("but_add",{ template:"<button @click = 'num++' >{{num}}</button>", data(){ return { num:1 } } }); //局部组件 const butaddzz = { template:"<button @click = 'num++' >{{num}}</button>", data(){ return { num:1 } } }; new Vue({ el:"#app", data:{ num:1 }, components:{ 'buttonadd':butaddzz } }); </script> </body> </html>

 

最新回复(0)