本文實例講述了微信小程序實現的一鍵復制功能。分享給大家供大家參考,具體如下:
微信小程序不支持頁面復制功能,故要實現某些信息的復制,需要開發復制功能
微信小程序中復制一般采用調用 wx.setClipboardData 接口
實現功能如下:
1,.wxml里寫一個復制按鈕
<button bindtap="copy"> 一鍵復制 </button>
2, .js里寫復制功能
copy: function (e) { var that = this; wx.setClipboardData({ data: "這里為復制的內容", success: function (res) { wx.showModal({ title: '提示', content: '復制成功', success: function (res) { if (res.confirm) { console.log('確定') } else if (res.cancel) { console.log('取消') } } }) } }); },如此即可實現復制功能了
wx.setClipboardData 接口詳細說明還可參考官方文檔:https://developers.weixin.qq.com/miniprogram/dev/api/wx.setClipboardData.html
希望本文所述對大家微信小程序開發有所幫助。
新聞熱點
疑難解答