<template>
<div>
<p class="grid" @click="copy(1)">222</p>
</div>
</template>
<script>
export default {
data() {
return {
}
},
methods: {
copy(item){
const input = document.createElement('input')
document.body.appendChild(input)
input.setAttribute('value',item)
input.select()
if (document.execCommand('copy')) {
document.execCommand('copy')
this.open2()
}
document.body.removeChild(input)
},
open2() {
this.$message({
message: '复制成功',
type: 'success'
});
}
},
}
</script>
<style>
.grid{
width: 20px;
height: 20px;
background: #0f0;
}
</style>
vue 触发点击事件,实现代码拷贝
最新推荐文章于 2024-07-19 10:30:06 发布