Vue.component('component-plus', { template: '#componentCount', props: ['compoCount'], methods: { plus: function() { this.compoCount +=1 } } }) /* Vue.component('component-plus', { template: ` <button @click="plus"> 我被按了 {{ compoCount }} 下 </button> `, props: { compoCount: String }, methods: { plus: function() { this.compoCount +=1 } } }) */ let vm = new Vue({ el: '#app', data: { count: 0 }, })
<div id="app"> <div is="component-plus" :compo-count='count' > </div> <component-plus :compo-count='count' > </component-plus> </div> <script type="text/x-template" id="componentCount"> <button @click="plus"> 我被按了 {{ compoCount }} 下 </button> </script>