vue剪切板功能

项目中用到了点击一个按钮,复制一段文字的功能

使用 vue-clipboard2

安装:使用下面的方式或者在package.json中配置好后 直接npm install

    npm install --save vue-clipboard2

在main.js中配置:

       import VueClipboard from 'vue-clipboard2'
       Vue.use(VueClipboard)

vue页面中使用:

  <template slot-scope="scope">
        <el-button 
               type="text" size="mini"
               v-clipboard:copy="scope.row.name"
               v-clipboard:success="copySuccess" 
                v-clipboard:error="onError">
                复制测点ID
        </el-button>                    
   </template>
 
    copySuccess(e) {
        this.$message({
          type: 'success',
          message: '复制测点ID成功!'
        });      
      },
 
      onError(e) {
        this.$message({
          type: 'error',
          message: '复制测点ID失败!'
        }); 
      },
 
 
原文地址:https://www.cnblogs.com/zuojiayi/p/13740282.html