在taro中利用定时器实现聊天室功能

在实现taro 的聊天室功能时,由于需求仅仅需要实现聊天,在线人数不多,使用频率较低,不想架构的太复杂,没有使用到websocket技术,,就想利用定时器定时获取数据再加载,服务端仅仅用传统接口来实现,数据存储在mysql,发现测试效果还是不错的。以下附上部分代码和思路

//重新刷新数据

  refreshChatData() {

    console.log('refreshChatData-------')

    this.loadChatData()

  }
 

//加载历史数据

  async loadChatData() {

    const currentChatKey = this.state.chatKey

    if (currentChatKey == '') {

      Taro.showToast({

        title: 'chatKey不能为空'

      })

      return

    }

    const payloadData = {

      chat_key: currentChatKey,

      user_id: this.paramUserId,

      access_token: ''

    }

    const oldChatData = this.state.chatData;

    const newChatData = await apiFetch({ url: '/api/C

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值