【微信小程序】TypeError: Cannot read property ‘get‘ of undefined & Error: MiniProgramError

简介: 【微信小程序】TypeError: Cannot read property ‘get‘ of undefined & Error: MiniProgramError



一、问题场景

  在写 uni-app 项目的时候,跟着视频一步一步的弄,一运行就发现报错了,然后就开始各种百度了。

找不到定义

WAServiceMainContext.js?t=wechat&s=1680006165208&v=2.30.2:1 TypeError: Cannot read property ‘get’ of undefined

at _callee$ (home.js? [sm]:16)

at L (regenerator.js:1)

at Generator._invoke (regenerator.js:1)

at Generator.t. [as next] (regenerator.js:1)

at asyncGeneratorStep (asyncToGenerator.js:1)

at c (asyncToGenerator.js:1)

at asyncToGenerator.js:1

at new Promise ()

at asyncToGenerator.js:1

at Proxy.getSwiperList (home.js? [sm]:15)(env: Windows,mp,1.06.2301160; lib: 2.30.2)

找不到请求路径

WAServiceMainContext.js?t=wechat&s=1680009054414&v=2.30.2:1 Error: MiniProgramError

{“errno”:600009,“errMsg”:“request:fail invalid url “/api/public/v1/home/swiperdata””}

at Object.errorReport (WAServiceMainContext.js?t=wechat&s=1680009054414&v=2.30.2:1)

at Function.thirdErrorReport (WAServiceMainContext.js?t=wechat&s=1680009054414&v=2.30.2:1)

at Object.thirdErrorReport (WAServiceMainContext.js?t=wechat&s=1680009054414&v=2.30.2:1)

at a (WASubContext.js?t=wechat&s=1680009054414&v=2.30.2:1)

at Object.cb (WASubContext.js?t=wechat&s=1680009054414&v=2.30.2:1)

at G._privEmit (WASubContext.js?t=wechat&s=1680009054414&v=2.30.2:1)

at G.emit (WASubContext.js?t=wechat&s=1680009054414&v=2.30.2:1)

at WASubContext.js?t=wechat&s=1680009054414&v=2.30.2:1

at Le (WASubContext.js?t=wechat&s=1680009054414&v=2.30.2:1)

at WASubContext.js?t=wechat&s=1680009054414&v=2.30.2:1(env: Windows,mp,1.06.2301160; lib: 2.30.2)

二、问题分析

  根据百度和ChatGPT,chatGPT回答如下:

  可以发现,原来是导入模块以及定义放在了 Vue3 定义中,导致页面上使用的时候找不到该引入。

// #ifndef VUE3

// #endif

三、问题解决

  将导入模块以及定义方式放在 // #ifndef VUE3 外面,这样就能解决问题了

import { $http } from '@escook/request-miniprogram'
uni.$http = $http
// 配置请求根路径
$http.baseUrl = 'https://www.uinav.com'
// #ifndef VUE3
import Vue from 'vue'
import App from './App'
// 请求拦截器
$http.beforeRequest = function(options){
  uni.showLoading({
    title:'数据加载中...'
  });
}
// 响应拦截器
$http.afterRequest = function(){
  uni.hideLoading();
}
Vue.config.productionTip = false
App.mpType = 'app'
const app = new Vue({
    ...App
})
app.$mount()
// #endif

  在微信开发者工具中也能请求到的 data 数据:


总结

  感谢观看,这里就是常用的视图容器类组件的介绍使用,如果觉得有帮助,请给文章点个赞吧,让更多的人看到。🌹 🌹 🌹

  也欢迎你,关注我。👍 👍 👍

  原创不易,还希望各位大佬支持一下,你们的点赞、收藏和留言对我真的很重要!!!💕 💕 💕 最后,本文仍有许多不足之处,欢迎各位认真读完文章的小伙伴们随时私信交流、批评指正!下期再见。

相关文章
|
8月前
|
存储 JavaScript 前端开发
成功解决:Cannot read properties of undefined (reading ‘commit‘)
这篇文章提供了解决Vuex中"Cannot read properties of undefined (reading 'commit')"错误的两种方法:检查模板中的数据属性是否存在,以及确保在Vue实例中正确挂载了store对象。
成功解决:Cannot read properties of undefined (reading ‘commit‘)
|
8月前
|
定位技术 Apache
Echarts——Invalid geoJson format Cannot read property 'length' of undefined
Echarts——Invalid geoJson format Cannot read property 'length' of undefined
149 0
|
8月前
|
JavaScript
VUE——filemanager-webpack-plugin报错TypeError: Cannot read property 'isFile' of undefined
VUE——filemanager-webpack-plugin报错TypeError: Cannot read property 'isFile' of undefined
179 0
|
8月前
|
前端开发 JavaScript
VUE——Uncaught (in promise) TypeError: Cannot read property '__esModule' of undefined
VUE——Uncaught (in promise) TypeError: Cannot read property '__esModule' of undefined
206 0
TypeError: Cannot set properties of undefined (setting ‘resdata‘),res定义数据出现的问题,定义的方法用this换成that
TypeError: Cannot set properties of undefined (setting ‘resdata‘),res定义数据出现的问题,定义的方法用this换成that
|
11天前
|
监控 前端开发 小程序
陪练,代练,护航,代打小程序源码/前端UNIAPP-VUE2.0开发 后端Thinkphp6管理/具备家政服务的综合型平台
这款APP通过技术创新,将代练、家政、娱乐社交等场景融合,打造“全能型生活服务生态圈”。以代练为切入点,提供模块化代码支持快速搭建平台,结合智能匹配与技能审核机制,拓展家政服务和商业管理功能。技术架构具备高安全性和扩展性,支持多业务复用,如押金冻结、录屏监控等功能跨领域应用。商业模式多元,包括交易抽成、增值服务及广告联名,同时设计跨领域积分体系提升用户粘性,实现生态共生与B端赋能。
65 9
|
3月前
|
移动开发 小程序
thinkphp+uniapp开发的多端商城系统源码/H5/小程序/APP支持DIY模板直播分销
thinkphp+uniapp开发的多端商城系统源码/H5/小程序/APP支持DIY模板直播分销
96 0
|
5月前
|
小程序 前端开发 JavaScript
在线课堂+工具组件小程序uniapp移动端源码
在线课堂+工具组件小程序uniapp移动端源码
121 0
在线课堂+工具组件小程序uniapp移动端源码
|
6月前
|
移动开发 小程序 数据可视化
基于npm CLI脚手架的uniapp项目创建、运行与打包全攻略(微信小程序、H5、APP全覆盖)
基于npm CLI脚手架的uniapp项目创建、运行与打包全攻略(微信小程序、H5、APP全覆盖)
849 3
|
6月前
|
小程序 API
微信小程序更新提醒uniapp
在小程序开发中,版本更新至关重要。本方案利用 `uni-app` 的 `uni.getUpdateManager()` API 在启动时检测版本更新,提示用户并提供立即更新选项,自动下载更新内容,并在更新完成后重启小程序以应用新版本。适用于微信小程序,确保用户始终使用最新版本。以下是实现步骤: ### 实现步骤 1. **创建更新方法**:在 `App.vue` 中创建 `updateApp` 方法用于检查小程序是否有新版本。 2. **测试**:添加编译模式并选择成功状态进行模拟测试。
141 0
微信小程序更新提醒uniapp

热门文章

最新文章