如何在vuex商店中使用axios实例属性?

问题描述 投票:2回答:1

我在main.js中创建了Axios Instance Properties:

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.js vuex
1个回答
2
投票

您可以导入Vue来使用它。

import Vue from 'vue'

async action() {
  const response = Vue.http.get('api/users');
}
© www.soinside.com 2019 - 2024. All rights reserved.