uniapp复制至剪贴板的使用

2021-01-19   阅读:444   分类:前端    标签: uni-app

uniapp小程序中,有时需要复制内容到剪贴板,可以使用以下方法实现点击按钮复制至手机剪贴板。

<template>
         <view>
                   <button type="default" @click="copy">复制</button>
         <view>
</template>

复制方法代码:

<script>
         export default {
                   methods: {  
                            copy(){
                                               wx.setClipboardData({
                                                        data: '我是文字',
                                                        success: function(res) {
                                                                 wx.getClipboardData({
                                                                           success: function(res) {
                                                                                    wx.showToast({
                                                                                             title: '复制成功'
                                                                                    });
                                                                           }
                                                                 });
                                                        }
                                               });
                                     }                 
                            }
         }
</script>


【腾讯云】618云上GO!云服务器限时秒杀,1核2G首年95元!

‘简忆博客’微信公众号 扫码关注‘简忆博客’微信公众号,获取最新文章动态
转载:请说明文章出处“来源简忆博客”。http://www.tpxhm.com/fdetail/586.html

×
觉得文章有用就打赏一下文章作者
微信扫一扫打赏 微信扫一扫打赏
支付宝扫一扫打赏 支付宝扫一扫打赏

文章评论(0)

登录
简忆博客壁纸 头像

简忆博客
勤于学习,乐于分享。

置顶推荐

打赏本站

如果你觉得本站很棒,可以通过扫码支付打赏哦!
微信扫码:你说多少就多少~
微信扫码
支付宝扫码:你说多少就多少~
支付宝扫码
×