vue 复制文字到剪切板

template
<template lang="pug">
input-group.pull-right.copyig(right, btn)
textarea.form-control(v-model='val', slot='input',ref='sendinfo')
button.btn.btn-ces(slot='right', @click="copyText",:disabled='showBtn') {{texts}}
</template>
script
props:{
val:String,
timer:{
type:Number,
default:2000
}
},
data(){
return{
texts:'点击复制',
showBtn:false
}
},
methods:{
setIg(){
Object.assign(this.$data, this.$options.data())
},
copyText(){
let def = this.$refs.sendinfo;
def.select()
document.execCommand("Copy");
this.texts='复制成功';
this.showBtn = true;
setTimeout(this.setIg,this.timer)
}
}

2 个评论

请问一下要是是复制P标签的怎么弄啊
只有textarea 才有select事件 你可以用css的方式 模拟p标签

要回复文章请先登录注册