TypeError: Cannot read property ‘get‘ of undefined

WAServiceMainContext.js?t=wechat&s=1679203309273&v=2.30.2:1 TypeError: Cannot read property 'get' of undefined
at _callee$ (home.js? [sm]:15)
at L (regenerator.js:1)
at Generator._invoke (regenerator.js:1)
at Generator.t.<computed> [as next] (regenerator.js:1)
at asyncGeneratorStep (asyncToGenerator.js:1)
at c (asyncToGenerator.js:1)
at asyncToGenerator.js:1
at new Promise (<anonymous>)
at asyncToGenerator.js:1
at Proxy.getSwiperList (home.js? [sm]:14)(env: Windows,mp,1.06.2303060; lib: 2.30.2)

需将导入的包和接口相关操作放在代码最前面

// 导入网络请求的包
import {
  $http
} from '@escook/request-miniprogram'

// 在 uni-app 项目中,可以把 $http 挂载到 uni 顶级对象之上,方便全局调用
uni.$http = $http

// 请求的根路径
$http.baseUrl = 'https://api-ugo-web.itheima.net'

// #ifndef VUE3
import Vue from 'vue'
import App from './App'

// 请求拦截器
$http.beforeRequest = function(options) {
  uni.showLoading({
    title: '数据加载中...'
  })
}

// 响应拦截器
$http.afterRequest = function() {
  wx.hideLoading()
}

Vue.config.productionTip = false

App.mpType = 'app'

const app = new Vue({
  ...App
})
app.$mount()
// #endif

// #ifdef VUE3
import {
  createSSRApp
} from 'vue'
import App from './App.vue'
export function createApp() {
  const app = createSSRApp(App)
  return {
    app
  }
}
// #endif

而且data访问数据也可以显示出来啦

methods: {
      async getSwiperList() {
        // const res = await uni.$http.get({url:'/api/public/v1/home/swiperdata', method:'GET'})
        const res = await uni.$http.get('/api/public/v1/home/swiperdata')
        console.log(res)
      }
    }

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值