[英]Nuxt: how do I access axios within the fetch() method?
我正在使用 nuxt 並且正在尋找一種從 nuxt fetch()
方法中訪問axios
對象的方法。 不幸的是,我似乎無法訪問它。 這是我試過的...
async fetch({store, params}) {
// const result = await axios.$get('/api/v2/inventory/3906?apiKey=xxx');
// const result = await this.axios.$get('/api/v2/inventory/3906?apiKey=xxx');
// const result = await $axios.$get('/api/v2/inventory/3906?apiKey=xxx');
store.commit('property/setProperty', result);
}
this
(顯然)不可用,並且$axios
和axios
未定義。
我確實在我的nuxt.config.js
定義了@nuxtjs/axios
nuxt.config.js
modules: [
'nuxt-buefy',
'@nuxtjs/style-resources',
'@nuxtjs/device',
'@nuxtjs/axios',
'@nuxtjs/proxy'
],
@balexandre 實際上應該為此獲得贊譽。 謝謝您的幫助。
這是我問的一個非常愚蠢的問題,但我會在這里發布答案,以防其他人有同樣的經歷。
import axios from 'axios' // don't forget me!
... later...
fetch() {
async fetch({store, params}) {
const result = await axios.get('/api/v2/inventory/3906?apiKey=xxx');
store.commit('property/setProperty', result);
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.