我对使用vuejs(2.0)还不熟悉.我正在try 降低此功能:
- 点击一个按钮
- 子组件中的触发函数
- 子数据中的增量数
这就是我现在拥有的
HTML:
<div id="root">
<cart @addtocart="add()"></cart>
<button @click="$emit('addtocart')">Add to Cart</button>
</div>
JS:
Vue.component('cart', {
template: `<span>{{ items }}</span>`,
data() {
return {
items: 0
}
},
methods: {
add() {
alert('add');
}
}
});
new Vue({
el: '#root',
components: ['cart'],
});
任何帮助都将不胜感激.谢谢大家!