vue.js - 如何在 vuex store 中使用 axios 实例属性?
问题描述
我在 main.js 中有板条箱 Axios 实例属性:
import Axios from "axios";
const axios = Axios.create({
baseURL: process.env.VUE_APP_BASE_URL
})
Vue.prototype.$http = axios;
我可以在 Vue 实例中使用它,但如何在store.js
商店vuex
中使用它?
this.$http
找不到。
TypeError: _this.$http is not a function
我得到了答案:
Use Vue.prototype.$http
解决方案
您可以导入Vue
使用它。
import Vue from 'vue'
async action() {
const response = Vue.http.get('api/users');
}
推荐阅读
- amazon-web-services - Terraform 更新 Cloudfront 分发
- php - Etag 未出现在 Laravel API 的标头中
- uicollectionview - 在 UICollectionViewController 中指定具体的单元格大小?
- shell - 将 Debian 9 (Stretch) Backports 添加到我的 sources.list
- python - Geodjango - 内存中的 r-tree 索引
- c# - 调用多个异步方法最终返回一个字符串值
- database - 使用 JS 保存和处理日期的正确结构是什么?
- json - JSON Feed 作为对象
- android - java.lang.string 无法转换为 JSONarray
- node.js - 中 sdk 的测试用例