欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Vue實(shí)現(xiàn)剪貼板復(fù)制功能

 更新時(shí)間:2019年12月31日 08:56:24   作者:NeverSettle  
這篇文章主要介紹了Vue實(shí)現(xiàn)剪貼板復(fù)制功能,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

小白單純記錄一下工作中遇到的需求:在vue中如何實(shí)現(xiàn)復(fù)制功能 (注: 依賴第三方插件 clipboard)

一. 安裝插件

第一種直接npm安裝: npm install clipboard --save

   第二種:  <script src="js/clipboard.min.js"></script>(下載地址:https://clipboardjs.com/

二. 全局注入(main.js)

import VueClipboard from 'vue-clipboard2'

  Vue.use(VueClipboard)

三. 封裝方法方便多次使用

新建一個(gè)index.js文件里面存放項(xiàng)目會(huì)多次使用的方法

export default{
  install(Vue,opstion){
    //把方法寫在vue原型方便調(diào)用
   Vue.prototype.copy = function (value) {
    this.$copyText(
     `${value}`
    ).then( res => {
     //這是element的Message 消息提示組件
      this.$message({
       message: "復(fù)制成功",
       type: "success"
      });
     },
     err => {
      this.$message.error("復(fù)制失敗");
     }
    );
   },
  }
}

四. 在需要復(fù)制的頁面中調(diào)用copy方法

<template>
     <el-tooltip class="item" effect="dark" content="復(fù)制" placement="bottom">
       <i class="icon copy iconfont" @click.stop="copyCode()"></i>
     </el-tooltip>
    </template>
    
    <script>
    
    //直接調(diào)用copy方法就可以了
      copyCode(scope) {
      //把需要復(fù)制的內(nèi)容傳value
         this.copy(scope.row.date);
       },
    </script>

總結(jié)

以上所述是小編給大家介紹的Vue實(shí)現(xiàn)剪貼板復(fù)制功能,希望對(duì)大家有所幫助!

相關(guān)文章

最新評(píng)論