# 1、安装

$ npm install vue-clipboard2  --save 
1

# 2、使用

  • main.js中引入,当然你也可以在单个页面中引入。 引入

  • 随便试试:

<template>
    <button class="btn" @click="doCopy">button</button>
</template>
1
2
3
doCopy() {
  this.$copyText('这里放入要粘贴的内容').then((e) => {
      // success
      console.log(e);
  }, (e) => {
      // fail
      console.log(e);
  });
}
1
2
3
4
5
6
7
8
9
  • 我们在panda-mall的个人信息页中使用了这个功能。

# 3、结语

  • 我这是采用github官网示例中sample2的写法,我觉得是最简单的实现方式,其他的你可以去看看官网;
  • 希望这个功能以后3分钟能搞定,不要再费十分钟。
Last Updated: 4/2/2020, 12:51:25 PM