当前位置:   article > 正文

TypeError: Cannot read property ‘get‘ of undefined

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)

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

  1. // 导入网络请求的包
  2. import {
  3. $http
  4. } from '@escook/request-miniprogram'
  5. // 在 uni-app 项目中,可以把 $http 挂载到 uni 顶级对象之上,方便全局调用
  6. uni.$http = $http
  7. // 请求的根路径
  8. $http.baseUrl = 'https://api-ugo-web.itheima.net'
  9. // #ifndef VUE3
  10. import Vue from 'vue'
  11. import App from './App'
  12. // 请求拦截器
  13. $http.beforeRequest = function(options) {
  14. uni.showLoading({
  15. title: '数据加载中...'
  16. })
  17. }
  18. // 响应拦截器
  19. $http.afterRequest = function() {
  20. wx.hideLoading()
  21. }
  22. Vue.config.productionTip = false
  23. App.mpType = 'app'
  24. const app = new Vue({
  25. ...App
  26. })
  27. app.$mount()
  28. // #endif
  29. // #ifdef VUE3
  30. import {
  31. createSSRApp
  32. } from 'vue'
  33. import App from './App.vue'
  34. export function createApp() {
  35. const app = createSSRApp(App)
  36. return {
  37. app
  38. }
  39. }
  40. // #endif

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

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

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/631411
推荐阅读
相关标签
  

闽ICP备14008679号