【问题标题】:Cannot read property 'get' of undefined on local host无法读取本地主机上未定义的属性“获取”
【发布时间】: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.jsmodules 数组中?
  • 你先运行npm i了吗?

标签: vue.js axios nuxt.js


【解决方案1】:

应该是这样的

asyncData({ $axios }) { 返回 $axios.$get('https://jsonplaceholder.typicode.com/todos/1') .then(响应 => { 返回{帖子:response.data} }) },

添加$get

【讨论】:

  • 错误信息很清楚:$axiosundefined。您的回答没有解决所提出的问题。在undefined 上调用get$get 并不重要。结果是一样的。
猜你喜欢
  • 2020-05-13
  • 2021-11-09
  • 2021-11-26
  • 1970-01-01
  • 2021-11-11
  • 1970-01-01
  • 2020-02-14
  • 2017-09-09
相关资源
最近更新 更多