Vue.component('click-count', { data: function() { return { count: 0 } }, template: ` <button @click="plus"> 我被按了 {{ count }} 下 </button> </button-counter> `, methods: { plus: function() { this.count+=1 } } }) let vm = new Vue({ el: '#app', /* data: { count: 0 }, methods: { plus: function() { this.count++ } } */ })
<div id="app"> <!-- <button-counter> <button @click="plus"> 我被按了 {{ count }} 下 </button> </button-counter> --> <click-count></click-count> <click-count></click-count> <click-count></click-count> <click-count></click-count> <click-count></click-count> </div>