微信小程序——小实现(禁止页面滚动、长按复制、长按识别二维码)

1. 禁止页面滚动

对于小程序某些一屏的页面,特别是全屏的swiper,并不希望页面在竖直方向上可以滚动。

实现方式:
在需要禁止滚动页面的json中加入:

"disableScroll": true

注意:只在页面配置中有效,无法再app.json中设置该项

参考:https://developers.weixin.qq.com/miniprogram/dev/framework/config.html#%E9%A1%B5%E9%9D%A2%E9%85%8D%E7%BD%AE

2. 长按复制

<text class='copy_content' bindlongpress='onLongTap'  >{{copyContent}}</text>

    onLongTap: function(e) {
      let that = this
      wx.setClipboardData({
        data: that.data.copyContent,
        success: function (res) {
          wx.showToast({
            title: '已复制到剪切板',
          });
        }
      })
    },

3. 长按识别二维码

其实,小程序里面是没有开放这个功能的。

有什么替代的方式?调取图片预览wx.previewImage(),在二维码放大预览时长按会出现‘发送给朋友’和‘保存图片’等选项,用户再自行进行二维码的扫描。

注意:如果图片中的二维码是小程序码,在预览时则可以识别并跳转。

<image class="qrCode" src="https://via.placeholder.com/400x400" data-src="https://via.placeholder.com/400x400" mode="aspectFit" bindlongpress="handlePress"></image>
Component({
  methods: {
    handlePress(e) {
      const _url = e.target.dataset.src;
      wx.previewImage({
        urls: [_url]
      })
    }
  }
})
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章