Javascript nuxt axios中的自定义函数

Javascript nuxt axios中的自定义函数,javascript,vue.js,axios,nuxt.js,Javascript,Vue.js,Axios,Nuxt.js,是否可以在nuxt axios async fetchSomething({ commit }) { const response = await this.$axios.customGet( `/blabla` ); await commit("setVideoData", response); } 这个customGet()可以有自己的baseUrl和自定义头 编辑以添加额外信息 这就是我添加到plugins/axios.js中的customGet

是否可以在
nuxt axios

async fetchSomething({ commit }) {
    const response = await this.$axios.customGet(
      `/blabla`
    );

    await commit("setVideoData", response);
  }
这个
customGet()
可以有自己的
baseUrl
和自定义头

编辑以添加额外信息

这就是我添加到plugins/axios.js中的
customGet()
函数

export default function({ $axios, store, redirect }) {
  $axios.customGet(body => {
    console.log("body from custom get", body);
  });
}
但不工作,我得到这个错误


您得到的是
TypeError
错误,因为您调用的是函数
customGet
(该函数不存在),而不是定义它

您的
插件/axios.js
应该如下所示:

export default function({ $axios, store, redirect }) {
    $axios.customGet = body => {
        /* The logic for customGet goes here */
        console.log("body from custom get", body);
    };
}

看起来您确实可以扩展axios。看一下.Hi@mgarcia,谢谢你的评论。我以前也尝试过类似的方法,但不起作用,请检查更新的问题。