Javascript TypeError:无法读取属性';获取';未定义-Vue资源和Nuxt的

Javascript TypeError:无法读取属性';获取';未定义-Vue资源和Nuxt的,javascript,vue.js,vuejs2,vuex,nuxt.js,Javascript,Vue.js,Vuejs2,Vuex,Nuxt.js,在我的Vuex商店中收到类似的错误 TypeError:无法读取未定义的属性“get” 我已经为vue资源添加了一个插件 这是我收到错误的代码 async getAllStudents({commit}) { await Vue.$http.get(`/api/students`) .then((res) => { if (res.status === 200) { commit('setAllStudents', res.data) } }).catc

在我的Vuex商店中收到类似的错误

TypeError:无法读取未定义的属性“get”

我已经为vue资源添加了一个插件

这是我收到错误的代码

async getAllStudents({commit}) {
await Vue.$http.get(`/api/students`)
  .then((res) => {
    if (res.status === 200) {
      commit('setAllStudents', res.data)
    }
  }).catch(function(error) {
    console.log(error);
  });

},

尝试使用
this
而不是
Vue
并尝试axios:

async getAllStudents({commit}) {
await this.$axios.get(`/api/students`)
  .then((res) => {
    if (res.status === 200) {
      commit('setAllStudents', res.data)
    }
  }).catch(function(error) {
    console.log(error);
  });
},

确保您的
numxt.config.js
如下所示:

const routerBase = process.env.DEPLOY_ENV === 'GH_PAGES' ? {
  router: {
    base: '/boussadjra-brahim/'
  }
} : {}

export default {
  mode: 'universal',
  /*
  ** Headers of the page
  */
  head: {
    titleTemplate: '%s - ' + 'Boussadjra Brahim',
    title: 'Boussadjra Brahim' || '',
    meta: [
      { charset: 'utf-8' },
      { name: 'viewport', content: 'width=device-width, initial-scale=1' },
      { hid: 'description', name: 'description', content: process.env.npm_package_description || '' }
    ],
    link: [
      { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }
    ],

  },

  /*
  ** Plugins to load before mounting the App
  */
  plugins: [
  ],

  ....
  /*
  ** Nuxt.js modules
  */
  modules: [
    // Doc: https://axios.nuxtjs.org/usage
    '@nuxtjs/axios',
  ],


  ....
}



试试这个,用
this.\u vm
代替
Vue

async getAllStudents({commit}) {
await this._vm.$http.get(`/api/students`)
  .then((res) => {
    if (res.status === 200) {
      commit('setAllStudents', res.data)
    }
  }).catch(function(error) {
    console.log(error);
  });
},

您在哪个文件中执行此操作?在我的店铺文件-/store/registration中谢谢兄弟。尝试了这个,效果很好,但我想更多地使用axios。重点是如何使用vue实例,因此您可以将axios与
一起使用。_vm.$axios.get