首先下载 npm i vue-clipboard2 -s
在main.js中使用
import VueClipboard from 'vue-clipboard2'
Vue.use(VueClipboard)
按需引入
例如:
<el-input v-model="link" maxlength="100" :rows="2" resize="none" placeholder="请填写链接" @focus="getLink" id="text">
<template slot="append">
<span class="el-icon-copy-document"
v-clipboard:copy="link" v-clipboard:success="copy"></span>
</template>
</el-input>
// 复制
copy(){
let text = document.getElementById('text').innerText;
this.$copyText(text).then((e) => {
}, (e) => {
this.$message.success("复制成功")
})
},