TypeError: Cannot read property 'split' of undefined百度一天也没解决,脑瓜疼。

img

img

img

登录成功后可以看到数据库也获取到用户登录信息,但是写入数据库就报错。没有写登录之前,自建的几个数据表正常使用。

现在把登录写好之后加了几个数据表模板,然后就全部数据表都无法写入了(全部都报错上面图一问题)。。读取能正常获取到数据,这是什么坑啊,百度了一天也没解决。

 userlogin() {
        uni.getUserProfile({
          desc: '用于完善会员资料', 
          success: res => {
            let user = res.userInfo 
            uni.setStorageSync('user', user)
            this.userinfo = user
          }
        })
        uni.login({
          provider: "weixin",
          success: (res) => {
            console.log(res)
            uniCloud.callFunction({
              name: 'logintest',//云函数logintest
              data: {
                code: res.code
              }
            }).then(res => {
              console.log(res)
            }).catch(res => {
              console.log(res)
            })
          }
        })
      },
//这是 云函数logintest
'use strict';
const uniID = require('uni-id')
exports.main = async (event, context) => {
  
  let res = await uniID.loginByWeixin({code:event.code});

  return res;
};
//云函数logintest end



//写入数据库
      add() {
       const db = uniCloud.database();
       const uniorder = db.collection('uni-id-base-order')
       uniorder.add({
         "title": "商品的标题",
         "type": "vip会员的订单",
       }).then(res => {
         console.log('写入数据库', res)
       })
      },


//读取数据库
      get() {
        const db = uniCloud.database();
        db.collection("uni-id-base-order").get().then((res) => {
          let data = res.result.data;
          console.log('获取数据库', data)
        }).catch((e) => {
          console.log(e)
        })
       }

没有看到哪里有用到split函数

没有贴代码,但是你可以通过注释有问题的代码,通过二分排查定位到问题代码在哪里。其次,应该是某个调用了split的变量是个undefined,加个判断,非空才处理。

你在哪里使用了split分割字符串啊?