首页 > 移动平台 > 详细

vue-clipboard2在ios,mac的异步方法中无法copy的问题

时间:2021-07-30 23:03:58      阅读:71      评论:0      收藏:0      [点我收藏+]

需求是需要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.

上面已经明确说明这个方法无法用在异步方法里面(原因未知,得花点时间把源码研究一下)

vue-clipboard2在ios,mac的异步方法中无法copy的问题

原文:https://www.cnblogs.com/zjhgx/p/15081222.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!