如果Vuejs是2.0以上 不再支持直接对 props:里面的数据直接操作 我们可以建立副本 再来操作
props:['answer','count'],
data() {
return {
voted :false ,
voted_count: this.count
}
},
computed: {
text() {
return this.voted_count
}
},
methods:{
vote() {
axios.post('/api/answer/vote',{'answer':this.answer}).then(response => {
this.voted = response.data.voted
response.data.voted ? this.voted_count ++ : this.voted_count --
})
}
}