uniapp axios在微信小程序出现index.js? [sm]:33 errortypeerror: l is not a function错误

在uniapp中使用axios请求接口,利用mock接口获取数据

在微信小程序运行时出错:index.js? [sm]:33 errortypeerror: l is not a function

原写法(在微信小程序不生效)

import axios from 'axios';
let _url = ' https://mobile-ms.uat.homecreditcfc.cn/mock/xxxxxxx/demo';
             axios.get(_url + '/demoInformation').then((res) => {
                 console.log(res);
                 console.log(res.data);
                 console.log(res.data.data.demoData);
              this.invoicesData = res.data.data.demoData;
             }).catch(function (error) {
                     // 处理错误情况
                     console.log(error);
                 });

解决办法:使用原生请求uni.request()

// 默认方式
uni.request({
    url: 'https://www.example.com/request',
    success: (res) => {
        console.log(res.data);
    },
    fail:(err) => {
        console.error(err)
    }
});

参考网址:https://uniapp.dcloud.io/api/README?id=vue-2
参考博客:https://blog.csdn.net/D505yjw/article/details/117415112

posted @ 2021-11-09 16:58  1940  阅读(713)  评论(0编辑  收藏  举报