复制这段代码 新建clipboard.js

//#ifdef H5
/** clipboard.js v2.0.4**/
!function(t,e){try{window.ClipboardJS=e();}catch(e){};"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.ClipboardJS=e():t.ClipboardJS=e()}(this,function(){return function(n){var o={};function r(t){if(o[t])return o[t].exports;var e=o[t]={i:t,l:!1,exports:{}};return n[t].call(e.exports,e,e.exports,r),e.l=!0,e.exports}return r.m=n,r.c=o,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=0)}([function(t,e,n){"use strict";var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},i=function(){function o(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}return function(t,e,n){return e&&o(t.prototype,e),n&&o(t,n),t}}(),a=o(n(1)),c=o(n(3)),u=o(n(4));function o(t){return t&&t.__esModule?t:{default:t}}var l=function(t){function o(t,e){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,o);var n=function(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}(this,(o.__proto__||Object.getPrototypeOf(o)).call(this));return n.resolveOptions(e),n.listenClick(t),n}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}(o,c.default),i(o,[{key:"resolveOptions",value:function(){var t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{};this.action="function"==typeof t.action?t.action:this.defaultAction,this.target="function"==typeof t.target?t.target:this.defaultTarget,this.text="function"==typeof t.text?t.text:this.defaultText,this.container="object"===r(t.container)?t.container:document.body}},{key:"listenClick",value:function(t){var e=this;this.listener=(0,u.default)(t,"click",function(t){return e.onClick(t)})}},{key:"onClick",value:function(t){var e=t.delegateTarget||t.currentTarget;this.clipboardAction&&(this.clipboardAction=null),this.clipboardAction=new a.default({action:this.action(e),target:this.target(e),text:this.text(e),container:this.container,trigger:e,emitter:this})}},{key:"defaultAction",value:function(t){return s("action",t)||'copy'}},{key:"defaultTarget",value:function(t){var e=s("target",t);if(e){return document.querySelector(e)}}},{key:"defaultText",value:function(t){return s("text",t)||this.text}},{key:"destroy",value:function(){this.listener.destroy(),this.clipboardAction&&(this.clipboardAction.destroy(),this.clipboardAction=null)}}],[{key:"isSupported",value:function(){var t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:["copy","cut"],e="string"==typeof t?[t]:t,n=!!document.queryCommandSupported;return e.forEach(function(t){n=n&&!!document.queryCommandSupported(t)}),n}}]),o}();function s(t,e){var n="data-clipboard-"+t;let isFun=e&&typeof e.hasAttribute==='function';if(isFun&&e.hasAttribute(n)){return e.getAttribute(n)}}t.exports=l},function(t,e,n){"use strict";var o,r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},i=function(){function o(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}return function(t,e,n){return e&&o(t.prototype,e),n&&o(t,n),t}}(),a=n(2),c=(o=a)&&o.__esModule?o:{default:o};var u=function(){function e(t){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),this.resolveOptions(t),this.initSelection()}return i(e,[{key:"resolveOptions",value:function(){var t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{};this.action=t.action,this.container=t.container,this.emitter=t.emitter,this.target=t.target,this.text=t.text,this.trigger=t.trigger,this.selectedText=""}},{key:"initSelection",value:function(){this.text?this.selectFake():this.target&&this.selectTarget()}},{key:"selectFake",value:function(){var t=this,e="rtl"==document.documentElement.getAttribute("dir");this.removeFake(),this.fakeHandlerCallback=function(){return t.removeFake()},this.fakeHandler=this.container.addEventListener("click",this.fakeHandlerCallback)||!0,this.fakeElem=document.createElement("textarea"),this.fakeElem.style.fontSize="12pt",this.fakeElem.style.border="0",this.fakeElem.style.padding="0",this.fakeElem.style.margin="0",this.fakeElem.style.position="absolute",this.fakeElem.style[e?"right":"left"]="-9999px";var n=window.pageYOffset||document.documentElement.scrollTop;this.fakeElem.style.top=n+"px",this.fakeElem.setAttribute("readonly",""),this.fakeElem.value=this.text,this.container.appendChild(this.fakeElem),this.selectedText=(0,c.default)(this.fakeElem),this.copyText()}},{key:"removeFake",value:function(){this.fakeHandler&&(this.container.removeEventListener("click",this.fakeHandlerCallback),this.fakeHandler=null,this.fakeHandlerCallback=null),this.fakeElem&&(this.container.removeChild(this.fakeElem),this.fakeElem=null)}},{key:"selectTarget",value:function(){this.selectedText=(0,c.default)(this.target),this.copyText()}},{key:"copyText",value:function(){var e=void 0;try{e=document.execCommand(this.action)}catch(t){e=!1}this.handleResult(e)}},{key:"handleResult",value:function(t){this.emitter.emit(t?"success":"error",{action:this.action,text:this.selectedText,trigger:this.trigger,clearSelection:this.clearSelection.bind(this)})}},{key:"clearSelection",value:function(){this.trigger&&this.trigger.focus(),window.getSelection().removeAllRanges()}},{key:"destroy",value:function(){this.removeFake()}},{key:"action",set:function(){var t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"copy";if(this._action=t,"copy"!==this._action&&"cut"!==this._action)throw new Error('Invalid "action" value, use either "copy" or "cut"')},get:function(){return this._action}},{key:"target",set:function(t){if(void 0!==t){if(!t||"object"!==(void 0===t?"undefined":r(t))||1!==t.nodeType)throw new Error('Invalid "target" value, use a valid Element');if("copy"===this.action&&t.hasAttribute("disabled"))throw new Error('Invalid "target" attribute. Please use "readonly" instead of "disabled" attribute');if("cut"===this.action&&(t.hasAttribute("readonly")||t.hasAttribute("disabled")))throw new Error('Invalid "target" attribute. You can\'t cut text from elements with "readonly" or "disabled" attributes');this._target=t}},get:function(){return this._target}}]),e}();t.exports=u},function(t,e){t.exports=function(t){var e;if("SELECT"===t.nodeName)t.focus(),e=t.value;else if("INPUT"===t.nodeName||"TEXTAREA"===t.nodeName){var n=t.hasAttribute("readonly");n||t.setAttribute("readonly",""),t.select(),t.setSelectionRange(0,t.value.length),n||t.removeAttribute("readonly"),e=t.value}else{t.hasAttribute("contenteditable")&&t.focus();var o=window.getSelection(),r=document.createRange();r.selectNodeContents(t),o.removeAllRanges(),o.addRange(r),e=o.toString()}return e}},function(t,e){function n(){}n.prototype={on:function(t,e,n){var o=this.e||(this.e={});return(o[t]||(o[t]=[])).push({fn:e,ctx:n}),this},once:function(t,e,n){var o=this;function r(){o.off(t,r),e.apply(n,arguments)}return r._=e,this.on(t,r,n)},emit:function(t){for(var e=[].slice.call(arguments,1),n=((this.e||(this.e={}))[t]||[]).slice(),o=0,r=n.length;o<r;o++)n[o].fn.apply(n[o].ctx,e);return this},off:function(t,e){var n=this.e||(this.e={}),o=n[t],r=[];if(o&&e)for(var i=0,a=o.length;i<a;i++)o[i].fn!==e&&o[i].fn._!==e&&r.push(o[i]);return r.length?n[t]=r:delete n[t],this}},t.exports=n},function(t,e,n){var d=n(5),h=n(6);t.exports=function(t,e,n){if(!t&&!e&&!n)throw new Error("Missing required arguments");if(!d.string(e))throw new TypeError("Second argument must be a String");if(!d.fn(n))throw new TypeError("Third argument must be a Function");if(d.node(t))return s=e,f=n,(l=t).addEventListener(s,f),{destroy:function(){l.removeEventListener(s,f)}};if(d.nodeList(t))return a=t,c=e,u=n,Array.prototype.forEach.call(a,function(t){t.addEventListener(c,u)}),{destroy:function(){Array.prototype.forEach.call(a,function(t){t.removeEventListener(c,u)})}};if(d.string(t))return o=t,r=e,i=n,h(document.body,o,r,i);throw new TypeError("First argument must be a String, HTMLElement, HTMLCollection, or NodeList");var o,r,i,a,c,u,l,s,f}},function(t,n){n.node=function(t){return void 0!==t&&t instanceof HTMLElement&&1===t.nodeType},n.nodeList=function(t){var e=Object.prototype.toString.call(t);return void 0!==t&&("[object NodeList]"===e||"[object HTMLCollection]"===e)&&"length"in t&&(0===t.length||n.node(t[0]))},n.string=function(t){return"string"==typeof t||t instanceof String},n.fn=function(t){return"[object Function]"===Object.prototype.toString.call(t)}},function(t,e,n){var a=n(7);function i(t,e,n,o,r){var i=function(e,n,t,o){return function(t){t.delegateTarget=a(t.target,n),t.delegateTarget&&o.call(e,t)}}.apply(this,arguments);return t.addEventListener(n,i,r),{destroy:function(){t.removeEventListener(n,i,r)}}}t.exports=function(t,e,n,o,r){return"function"==typeof t.addEventListener?i.apply(null,arguments):"function"==typeof n?i.bind(null,document).apply(null,arguments):("string"==typeof t&&(t=document.querySelectorAll(t)),Array.prototype.map.call(t,function(t){return i(t,e,n,o,r)}))}},function(t,e){if("undefined"!=typeof Element&&!Element.prototype.matches){var n=Element.prototype;n.matches=n.matchesSelector||n.mozMatchesSelector||n.msMatchesSelector||n.oMatchesSelector||n.webkitMatchesSelector}t.exports=function(t,e){for(;t&&9!==t.nodeType;){if("function"==typeof t.matches&&t.matches(e))return t;t=t.parentNode}}}])});let Types={isFunction:function(obj){var type=Object.prototype.toString.call(obj)return type=='[object Function]'},isObject:function(obj){var type=Object.prototype.toString.call(obj)return type=='[object Object]'},isString:function(obj){var type=Object.prototype.toString.call(obj)return type=='[object String]'}}
uni.setClipboardData=function(options){let emptyFun=function(){}let config={data:null,event:null,success:emptyFun,fail:emptyFun,complete:emptyFun}if(options&&Types.isObject(options)){config=Object.assign({},config,options)}if(options&&Types.isString(options)){config=Object.assign({},config,{data:options})}let data=config.datalet success=config.success||emptyFunlet fail=config.fail||emptyFunlet complete=config.complete||emptyFunlet e=config.event||window.event||{}let cb=new ClipboardJS('.null',{text:()=>data})cb.on('success',function(res){window.__clipboard__=data;success&&Types.isFunction(success)&&success({data:res.text})complete&&Types.isFunction(complete)&&complete()cb.off('error')cb.off('success')cb.destroy()})cb.on('error',function(err){fail&&Types.isFunction(fail)&&fail(err)complete&&Types.isFunction(complete)&&complete()cb.off('error')cb.off('success')cb.destroy()})cb.onClick(e)};
uni.getClipboardData=function(options){let emptyFun=function(){}let config={data:null,event:null,success:emptyFun,fail:emptyFun,complete:emptyFun}if(options&&Types.isObject(options)){config=Object.assign({},config,options)}let success=config.success||emptyFunlet fail=config.fail||emptyFunlet complete=config.complete||emptyFunif(window.__clipboard__!==undefined){success&&Types.isFunction(success)&&success({data:window.__clipboard__})}else{fail&&Types.isFunction(fail)&&fail({data:null})}complete&&Types.isFunction(complete)&&complete()};
function fileDownLoad(data){var linkElement=document.createElement('a')linkElement.setAttribute('href',data.blob)linkElement.setAttribute('downLoad',data.name)linkElement.click()}
uni.saveImageToPhotosAlbum=uni.saveVideoToPhotosAlbum=function(options){let emptyFun=function(){}let config={filePath:null,success:emptyFun,fail:emptyFun,complete:emptyFun}if(options&&Types.isObject(options)){config=Object.assign({},config,options)}if(options&&Types.isString(options)){config=Object.assign({},config,{filePath:options})}let filePath=config.filePathlet success=config.success||emptyFunlet fail=config.fail||emptyFunlet complete=config.complete||emptyFunif(!filePath){fail&&Types.isFunction(fail)&&fail({msg:'no File'})complete&&Types.isFunction(complete)&&complete()return}let names=filePath.split('/')let name=names[names.length-1]uni.downloadFile({url:filePath,success:function(res){let tempFilePath=res.tempFilePathfileDownLoad({name:name,blob:tempFilePath})success&&Types.isFunction(success)&&success({filePath:filePath})},fail:function(err){fail&&Types.isFunction(fail)&&fail({msg:err})},complete:function(){complete&&Types.isFunction(complete)&&complete()}})}
//#endif

在main.js里面引用

import icanH5Api from '@/utils/clipboard.js'

然后在使用的页面写一个copyClick函数调用

         // 复制到粘贴板copyClick(e) {uni.showModal({content: e,//模板中提示的内容confirmText: '复制内容',success:()=>{//点击复制内容的后调函数//uni.setClipboardData方法就是讲内容复制到粘贴板uni.setClipboardData({data: e,//要被复制的内容success:()=>{//复制成功的回调函数uni.showToast({//提示title:'复制成功'})}});}});},

uniapp H5 公众号 复制内容 复制文本 API `setClipboardData` is not yet implemented 怎么处理?相关推荐

  1. uni-app - H5 公众号网页分享到微信朋友圈 / 转发分享给朋友好友 / 分享到手机 QQ / 分享到 QQ 空间,给微信分享卡片设置图标、标题、描述文字等(JS-SDK 通用解决方案放心用)

    前言 如果您是纯 Vue.js 项目(或 Nuxt.js),请访问 Vue - 最新网页 H5 分享到微信朋友圈 / 转发分享好友 这篇详细教程. 目前网上大部分教程都过时了(老版本.无效),并且未对 ...

  2. uniapp h5 公众号 自定义卡片式分享链接

    描述: 首次开发卡片式分享链接,过程中遇到许多坑,查阅了几十篇博客终于完成了这个功能,记录的开发过程不一定符合你的需求,但如果你也是用uniapp开发,希望本篇能够帮助到你. 效果图: 准备工作: 设 ...

  3. uniapp H5 公众号授权

    微信网页授权,我们都知道有两种,一种是静默授权,一种是需要用户同意的授权.两种授权方式的区别就在于 ,静默授权自动跳转到回调页面,拿取到的信息只要用户的openid,而另外一种弹窗授权,则可以拿到用户 ...

  4. uniapp h5 公众号 支付

    接入前准备 下面封装好的方法 将接口返回的参数替换掉就可以了 function onBridgeReady(url, data, callback) {uni.request({url: api[ur ...

  5. uniapp h5公众号授权登录基本流程

    公众号授权登录流程 1.判断登陆情况,直接就是拿本地存储的token去请求接口,401就是未授权或者授权过期 2.未登录: url地址有code 直接获取code,请求登陆接口 url地址无code ...

  6. 如何查找自己的微信公众号主页并复制链接

    如何查找自己的微信公众号主页并复制链接 随意复制你微信公众号的一篇文章链接在浏览器打开查看源代码 找到biz=*****编码,例如biz=MzUwOTg2MzgyMw https://mp.weixi ...

  7. 公众号点击图片变成另一张_公众号互动内容:小众潮流or下一个风口?| 新榜观察...

    你有多久没沉下心来,在微信里读一篇长文了? 微信公众号生态日趋饱和.这两年的流行趋势是条漫式写作--这不仅仅指长图推送,也包括"两行字+一张图"排版方式.用户的注意力被切得七零八落 ...

  8. 公众号点击图片变成另一张_公众号互动内容:小众潮流or下一个风口?

    你有多久没沉下心来,在微信里读一篇长文了? 微信公众号生态日趋饱和.这两年的流行趋势是条漫式写作--这不仅仅指长图推送,也包括"两行字+一张图"排版方式. 用户的注意力被切得七零八 ...

  9. PHP开发B2C商城 微信小程序商城系统源码+数据库,轻量级前后端分离的电商系统,支持微信小程序 + H5+ 公众号 + APP

    项目介绍 一款轻量级.高性能.前后端分离的电商系统,支持微信小程序 + H5+ 公众号 + APP,前后端源码完全开源,看见及所得,完美支持二次开发,可学习可商用,让您快速搭建个性化独立商城. 完整代 ...

最新文章

  1. configure: error: no acceptable C compiler found in $PATH
  2. System.Threading.Timer使用心得
  3. Parameter 对象
  4. Reveal.js:把你的 Markdown 文稿变成 PPT
  5. PowerDesigner教程系列(五)概念数据模型
  6. 智慧城市java开发_智慧城市主界面开发 使用eclipse开发智慧城市APP源码 - 下载 - 搜珍网...
  7. 囚徒困境(博弈论的诡计)
  8. 解锁设备_苹果新专利:用户可通过头显设备快速解锁多个附近设备
  9. 【万用表识别】基于matlab数字仪表识别【含Matlab源码 693期】
  10. GMSK调制 MATLAB代码
  11. HttpClient4.x使用中出现的几个问题及解决方法
  12. jsonp 跨域 java_Java web支持jsonp跨域
  13. matlab消除多重共线性,多重共线性问题的几种解决方法-解决多重共线性的方法...
  14. 仿淘宝商品详情页[带有视频和图片的轮播功能]
  15. python做马尔科夫模型预测法_李航《统计学习方法》第十章——用Python实现隐马尔科夫模型...
  16. 淘宝爆款打造公式(仅供参考)
  17. 科学计算机怎么编程玩,如何通过可编程科学计算器在另一个设备中运行本机MFP语言编写的...
  18. 关于GPS经纬度如何转百度经纬度
  19. apoint.exe
  20. 在木星和土星上,钻石如雨般下落

热门文章

  1. 2018国际体验设计大会圆满闭幕,IXDC发挥“设计外交”作用
  2. LeetCode每日一题——380. O(1) 时间插入、删除和获取随机元素
  3. LOJ #10222. 「一本通 6.5 例 4」佳佳的 Fibonacci
  4. 飞信真的值得推荐de理由
  5. SQL DML 数据操纵语句
  6. MDK解决方案:error: #29: expected an expression
  7. 【Java】基于Pdfbox解析PDF文档中指定位置的文字和图片
  8. Android-蓝牙开发:解决搜索不到蓝牙设备
  9. Vue案例:组件之间的传值问题
  10. GraphTCN: Spatio-Temporal Interaction Modeling for Human Trajectory Prediction