uni-app踩坑集合(小程序)

1.指定页面不显示返回或首页按钮

onShow(){
   
uni.h
}

在这里插入图片描述

2.uni-app 开发微信小程序长按识别公众号
![在这里插入图片描述](https://img-blog.csdnimg.cn/c50573de78f54402955ece64fa1b9864.png#pic_center

/*
*思路:
*1.使用公众号的文章分享二维码图片(若无需在公众号发布文章,然后使用该篇文章的分享二维码)
*2.使用image标签的show-menu-by-longpress属性
*show-menu-by-longpress开启长按识别功能
*/
<template>
      <image
        v-if="popupURL"
        show-menu-by-longpress
        :src="popupURL"
        alt=""
        class="popupURL-box"
      />
 </template>

3.uni-app 开发微信小程序 推荐并携带推荐人信息小程序码
在这里插入图片描述

/*
*思路:
*1.获取小程序的token(APPID--微信公众平台-》开发管理-》开发设置获取,APPSECRET--微信公众平台-》开发管理-》开发设置获取)
*2.?id=或者scene 为携带的参数
*3.QRCode 生成小程序码
*4.getToken接口调用和getQrCode接口建议使用后台接口完成
*/
/*推荐页面
*/
<script>
import QRCode from './../../../common/weapp-qrcode.js'
  methods: {
   
    getToken() {
   
      uni.showLoading({
   
        title: '加载中',
        mask: true,
      })
      let APPID = '******'
      let APPSECRET = '******'
      uni
        .request({
   
          url: `https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=${
     APPID}&secret=${
     APPSECRET}`,
          method: 'GET',
        })
        .then((res) => {
   
          if (res[1].data.expires_in != 7200) {
   
            uni.showToast({
   
              title: '分享失败,请重新尝试。',
              icon: 'none',
              duration: 2000,
            })
            uni.hideLoading()
            return
          }
          this.getQrCode(res[1].data.access_token)
          uni.hideLoading()
        })
        .catch((err) => {
   
          console.log(err)
          uni.hideLoading()
        })
    },
    getQrCode(access_token) {
   
      let scene =
        'id=' + uni.getStorageSync('userInfo').additionalInformation.userId
      //获取小程序码带参数
      const that = this
      uni.request({
   
        url:
          'https://api.weixin.qq.com/wxa/getwxacode?access_token=' +
          access_token, //固定链接,不用改
        method: 'POST',
        responseType: 'arraybuffer', //设置响应类型
        data: {
   
          scene: scene,
          path:
            'pages/login/login?id=' +
            uni.getStorageSync('userInfo').additionalInformation.userId, // 必须是已经发布的小程序存在的页面(否则报错) ()
          width: 200,
          auto_color: true, // 自动配置线条颜色,如果颜色依然是黑色,则说明不建议配置主色调
          line_color: {
   
            r: '0',
            g: '0',
            b: '0',
          }, // auto_color 为 false 时生效,使用 rgb 设置颜色
        },
        success: function (res) {
   
          console.log('获取二维码', res) //返回的是ArrayBuffer 对象
          setTimeout(() => {
   
            that.popupURL =
              'data:image/PNG;BASE64,' + uni.arrayBufferToBase64(res.data) //以图片的形式展示
          }, 50)
        },
      })
    },
   }
</script>
/*获取
*/
<script>
  onLoad(options) {
   
    uni.setStorageSync('accountId', options.id)
  },
  </script>
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值