0
从以下简单书签交易状例如开始:https://jsfiddle.net/coligo/g7mu5ndz/Vuejs:组件聚合
Vue.component('post', {
template: "#post-template",
props: ['post'],
data: function() {
return {
upvoted: false,
downvoted: false
};
},
methods: {
upvote: function() {
this.upvoted = !this.upvoted;
this.downvoted = false;
},
downvote: function() {
this.downvoted = !this.downvoted;
this.upvoted = false;
}
},
computed: {
votes: function() {
if (this.upvoted) {
return this.post.votes + 1;
} else if (this.downvoted) {
return this.post.votes - 1;
} else {
return this.post.votes;
}
}
}
});
var vm = new Vue({
el: "#app",
data: {
posts: [{
title: "A post for our reddit demo starting at 15 votes",
votes: 15
},
{
title: "Try out the upvoting, it works, I promise",
votes: 53
},
{
title: "coligo is the bomb!",
votes: 10
}]
}
});
我想:
- 一个)显示upvotes的总数(列表下的帖子,在#APP DIV
- b)对于每一个职位,显示它已获得
这可能没有管理父级中的每个发布状态吗?
感谢指向自定义事件文档,这是拼图的一角。这最终会导致父母的大部分逻辑,但我认为这是一条可行的路线,而且它完美地工作。 – nielahwaes