获取存储数据

一.获取用户openID

WXML:

<view class="container">
  <view class="userinfo">
    <block wx:if="{{!hasUserInfo}}">
      <button wx:if="{{canIUseGetUserProfile}}" bindtap="getUserProfile"> 获取头像昵称 </button>
      <button wx:else open-type="getUserInfo" bindgetuserinfo="getUserInfo"> 获取头像昵称 </button>
    </block>
    <block wx:else>
      <image bindtap="bindViewTap" class="userinfo-avatar" src="{{userInfo.avatarUrl}}" mode="cover"></image>
      <text class="userinfo-nickname">{{userInfo.nickName}}</text>
    </block>
  </view>
</view>

js:

Page({
  data: {
    userInfo: {},
    hasUserInfo: false,
    canIUseGetUserProfile: false,
  },
  onLoad() {
    if (wx.getUserProfile) {
      this.setData({
        canIUseGetUserProfile: true
      })
    }
  },
  getUserProfile(e) {
    wx.getUserProfile({
      desc: '用途', 
      success: (res) => {
        this.setData({
          userInfo: res.userInfo,
          hasUserInfo: true
        })
      }
    })
  },
})

​

页面产生点击事件时调用,每次请求都会弹出授权窗口,用户同意后返回 userInfo

二.根据用户openID获取数据

getmyinfo:function(){
    let that=this
    db.collection('POST').where(_.or([
      {openID:res.result.openid},          //判断是否是组织创建者
      ]))
    .get({
      success(res){
        console.log("请求成功",res)
        that.setData({
          datalist: res.data
        })
      },
      fail(res){
        console.log("请求失败",res)
      }
  })
  },

由于数据库中存放的是FIleID,因此需要在获得数据后再根据FilID将信息展示出来。

三.显示信息

WXML:

<view wx:for='{{testList}}' wx:for-item="item">
     <image src="{{item.postimages}}"></image>
</view>

js:

const db = wx.cloud.database()
const $ = db.command.aggregate
const _ = db.command

Page({
  data: {
    testList:[],
    },
  
  onLoad: function() {
  //获取云端数据库的数据
    const db = wx.cloud.database()
    db.collection('POST').get({
      success:res=> {
        console.log(res.data)
        this.setData({
          testList:res.data,
        })
      },
      fail: console.error
    })
  }
})

如此就可以将存储中的图片显示出来

参考

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值