欢迎您 本站地址:
复制网址
手机查看
切换背景
返回首页
返回编程教学
源代码:
html编辑器
颜色值转换
点击运行
Vue 测试实例 - 小库网 <script src="https://cdn.staticfile.net/vue/2.2.2/vue.min.js"></script> <div id="app"> <div id="counter-event-example"> <p>{{ total }}</p> <button-counter v-on:increment="incrementTotal"></button-counter> <button-counter v-on:increment="incrementTotal"></button-counter> </div> </div> <script> Vue.component('button-counter', { template: '<button v-on:click="incrementHandler">{{ counter }}</button>', data: function () { return { counter: 0 } }, methods: { incrementHandler: function () { this.counter += 1 this.$emit('increment') } }, }) new Vue({ el: '#counter-event-example', data: { total: 0 }, methods: { incrementTotal: function () { this.total += 1 } } }) </script>
运行结果:
小库提示
扫描下方二维码,访问手机版。
打赏
关闭