【发布时间】:2021-03-29 23:21:18
【问题描述】:
使用 Vue.Js,当我尝试在本地主机上运行时,我收到错误 Cannot read property 'get' of undefined
它指的是 my.get 请求。有什么建议吗?
export default {
asyncData({ $axios }) {
return $axios.get('https://jsonplaceholder.typicode.com/todos/1')
.then(response => {
return { posts: response.data }
})
},
【问题讨论】:
-
可能需要在导出前加上
const $axios = require('axios'); -
请分享 nuxt.config.js 文件
-
除了您的
$axios变量未定义外,您还需要调用$get而不是get。 -
您的项目中是否安装了
@nuxtjs/axios包并存在于nuxt.config.js的modules数组中? -
你先运行
npm i了吗?