写了两个按钮,用muse-ui.
结果第一次关注时无法切换(但请求发出去了,此时点击其它的“取消关注”才会切换。)
刷新后,已是“取消关注”的功能正常。
//这是按钮:
<mu-flat-button label="+ 关注" class="demo-flat-button" v-if="!item.user_followed" @click="myFollow(item)" />
<mu-flat-button label="已关注" class="demo-flat-button" id="followed" v-else="item.user_followed" @click="unFollow(item)"/>
//对应方法及请求
methods:{
//关注
myFollow (item) {
var _this = this;
axios.post('关注的请求‘).then(function (res) {
item.user_followed = true
})
},
//取消关注
unFollow (item) {
var _this = this;
axios.post('取消关注的请求').then(function (res) {
item.user_followed = false
})
}
}
我对vue不是太熟悉,并且不知道你vue.List代表是什么
但是,
_this.List.splice(_this.List.indexOf(item), 1, item)这段代码有没有问题呢?
如果第一次关注,_this.List.indexOf(item)肯定是返回-1的
这里,你改成这样试试,v-if改为v-show