uni-app中判断auth.uid是否不为null

uni-app中判断auth.uid是否不为null

3 回复

auth.uid依赖于uni-id,请检查一下,是否是登录状态

更多关于uni-app中判断auth.uid是否不为null的实战教程也可以访问 https://www.itying.com/category-93-b0.html


找到问题了,数据库触发器里查询时没有添加 user_id == dbJQL.getCloudEnv(’$cloudEnv_uid’)

在 Uni-App 中,如果你使用了类似 Firebase 或 UniCloud 的服务,并且需要判断 auth.uid 是否不为 null,你可以使用 JavaScript 的条件判断语句来实现。

假设 auth 是一个包含 uid 属性的对象,你可以这样判断:

if (auth && auth.uid !== null && auth.uid !== undefined) {
  console.log('uid 存在且不为 null');
  // 在这里执行你的逻辑
} else {
  console.log('uid 不存在或为 null');
  // 在这里处理 uid 不存在或为 null 的情况
}

解释:

  1. auth && auth.uid !== null && auth.uid !== undefined:

    • auth 检查 auth 对象是否存在。
    • auth.uid !== null 检查 uid 是否为 null
    • auth.uid !== undefined 检查 uid 是否为 undefined
  2. console.log:

    • 你可以根据实际需求替换为其他逻辑,比如跳转页面、显示提示信息等。

示例:

假设你在 onLoad 生命周期函数中使用:

onLoad() {
  const auth = uni.getStorageSync('auth'); // 假设 auth 是从本地存储中获取的
  if (auth && auth.uid !== null && auth.uid !== undefined) {
    console.log('uid 存在且不为 null');
    // 执行需要 uid 的逻辑
  } else {
    console.log('uid 不存在或为 null');
    // 处理 uid 不存在或为 null 的情况
  }
}
回到顶部