从hbuilder中编译到微信开发者工具,提示如下错误
ReferenceError: uni is not defined
at request.js? [sm]:31
at new Promise (<anonymous>)
at _callee$ (request.js? [sm]:20)
at s (regeneratorRuntime.js:1)
at Generator.<anonymous> (regeneratorRuntime.js:1)
at Generator.next (regeneratorRuntime.js:1)
at asyncGeneratorStep (asyncToGenerator.js:1)
at c (asyncToGenerator.js:1)
at asyncToGenerator.js:1
at new Promise (<anonymous>)(env: macOS,mp,1.06.2405020; lib: 3.4.10)
这个问题应该如何解决,以前在VUE2中没有出现过这个问题,改成vue3之后,这个就报错了
x***@163.com (作者)
封装了一个方法
const request = async (method = "GET", url, data, header = {
'content-type': 'application/json'
}, isShowLoading = false) => {
return new Promise(function(resolve, reject) {
if (isShowLoading) {
uni.showLoading({
title: "加载中...",
success(res) {},
fail(res) {
console.error(
showLoading调用失败
);},
});
}
let accessToken = uni.getStorageSync("accessToken")
})
放在了js文件中,在main.js中引入了
import {request} from '@/static/utils/request.js'
并设置了,全局绑定http请求
app.config.globalProperties.$http = request
,在App.vue文件中onLaunch的生命周期中调用了封装的request方法,然后uni这个变量提示ReferenceError: uni is not defined的错误
2024-07-19 10:55