javascript - 在 Vue 中的 axios 请求后更新关注状态
问题描述
我需要在 axios 请求后更新关注取消关注按钮
<template>
<div v-if="isnot">
<a href="#" @click.prevent="unfellow" v-if="isfollowing" >unFellow</a>
<a href="#" @click.prevent="fellow" v-else >Fellow</a>
</div>
</template>
我的方法
fellow () {
axios.post(`/@${this.follower}/follow/`)
},
unfellow () {
axios.post(`/@${this.follower}/unfollow/`)
},
}
解决方案
一个基本的例子:
fellow () {
var self = this;
axios.post(`/@${this.follower}/follow/`)
.then(function (response) {
self.isfollowing = true;
})
.catch(function (error) {
console.log( error.response.data);
});
},
推荐阅读
- scala - IntelliJ 在 udf 函数上构建了一个有 2 个错误的项目 - 没有可用于 Option[Seq[Testclass]] 的 TypeTag
- smalltalk - 最佳流大小(ReadStream、WriteStream 等)
- php - 逻辑与运算符的奇怪行为
- java - 在 Ant 任务中设置 JAVA OPTS
- python - 如何在 odoo 11 中使用报告打印记录?
- mongodb - Mongodb 嵌套数组聚合
- python - 画字母python
- firebase - Firebase 的“时间戳”值可以在客户端代码中轻松篡改吗?
- eclipse - 在 Eclipse neon cdt 中安装 ShellEd 插件时出现问题
- sql - 我有一份包含事实表和暗表的报告,我该如何分析这些表?我刚刚开始学习商业智能