x***@163.com
x***@163.com
  • 发布:2024-07-19 10:29
  • 更新:2024-07-19 10:55
  • 阅读:151

Vue3 下ReferenceError: uni is not defined

分类:uni-app

从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之后,这个就报错了

2024-07-19 10:29 负责人:无 分享
已邀请:
DCloud_UNI_yuhe

DCloud_UNI_yuhe

uni在哪调用的,详细说一下

  • 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

DCloud_UNI_yuhe

DCloud_UNI_yuhe

static,是这个,放别的文件夹里面

  • 1***@qq.com

    啥意思,没看懂,我也遇到这种问题

    2024-08-19 14:59

  • DCloud_UNI_yuhe

    回复 1***@qq.com: js文件不要放到static文件夹下

    2024-08-19 15:07

要回复问题请先登录注册