标签:taobaoPwd vue console log res ios mac copy
需求是需要copy从后台接口返回的字符串到剪切板,在mac 的chrome,android 微信,浏览器中测试都可以,但在iphone safari,微信,还有mac 的safari中copy都失败
this.$axios.get(`${this.host}/goods/go/${code}`).then((res) => { console.log('res = ' + res.data); this.taobaoPwd = res.data; console.log('taobaoPwd = ' + res.data); let that = this; this.$copyText(this.taobaoPwd).then( function (e) { console.log(e); that.showing = true; }, function (e) { alert('Can not copy'); console.log(e); }, );
因为this.$copyText是在$axios这个异步方法里的,而在vue-clipboard2主页上有一句话,[https://github.com/Inndy/vue-clipboard2]
Yes, you can do it by using our new method: this.$copyText. See sample2, where we replace the clipboard directives with a v-on directive. Modern browsers have some limitations like that you can't use window.open without a user interaction. So there's the same restriction on copying things! Test it before you use it.
Make sure you are not using this method inside any async method.
上面已经明确说明这个方法无法用在异步方法里面(原因未知,得花点时间把源码研究一下)
标签:taobaoPwd,vue,console,log,res,ios,mac,copy 来源: https://www.cnblogs.com/zjhgx/p/15081222.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。