首页 > 解决方案 > 如何在 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.jsvuex

解决方案


您可以导入Vue使用它。

import Vue from 'vue'

async action() {
  const response = Vue.http.get('api/users');
}

推荐阅读