vue 点击复制链接功能

mac2023-01-25  42

代码 template里

<p class="inviteCode" id = "inviteCode" v-text="short_url"></p> <el-button v-if="short_url" class="copy" @click="CopyUrl">复制链接</el-button>

在methods里

```javascript // 复制 CopyUrl(data){ var Url2 = document.getElementById("inviteCode").innerText; var oInput = document.createElement("input"); oInput.value = Url2; document.body.appendChild(oInput); oInput.select(); // 选择对象 document.execCommand("Copy"); // 执行浏览器复制命令 oInput.className = "oInput"; oInput.style.display = "none"; this.$message({ message:"复制成功!", type:'success' }) },

复制干嘛? 楞着呀!

最新回复(0)