Vue组件注册注意事项上
1 <!DOCTYPE html> 2 <html lang="en"> 3 4 <head> 5 <meta charset="UTF-8"> 6 <meta http-equiv="X-UA-Compatible" content="IE=edge"> 7 <meta name="viewport" content="width=device-width, initial-scale=1.0"> 8 <title>组件注册注意</title> 9 </head> 10 11 <body> 12 <div id="app"> 13 <button-counter></button-counter> 14 <button-counter></button-counter> 15 <button-counter></button-counter> 16 </div> 17 </body> 18 <script src="../js/vue.js"></script> 19 <script> 20 /* 21 组件注意事项 22 1.组件参数的data值必须是函数 23 2.组件模板必须是单个根元素 24 3.组件模板的内容可以是模板字符串 25 */ 26 Vue.component('button-counter', { 27 data: function () { 28 return { 29 count: 0 30 } 31 32 }, 33 template: ` 34 <div> 35 <button @click='handle'>点击了{{count}}</button> 36 <button>测试123</button> 37 </div> 38 `, 39 methods: { 40 handle: function () { 41 this.count += 2; 42 } 43 } 44 }) 45 46 var vm = new Vue({ 47 el: '#app', 48 data: { 49 50 } 51 }) 52 </script> 53 54 </html>
道阻且长,行则将至

浙公网安备 33010602011771号