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]
})
}
}
})