在业务需求中,需要实现点击复制链接的功能
话不多说,直接上代码
<div class&#61;"profile_inner_middlelink"><div class&#61;"profile_inner_middlelink_http">{{httpLink}}</div><el-button type&#61;"primary" &#64;click&#61;"handleCopy()" plain>复制链接</el-button></div>
data() {return {httpLink: "https://www.baidu.com/",}
}
methods方法&#xff1a;
handleCopy() {this.copy(this.httpLink)
},
copy(data) {let url &#61; data;let oInput &#61; document.createElement(&#39;input&#39;);oInput.value &#61; url;document.body.appendChild(oInput);oInput.select(); console.log(oInput.value)document.execCommand("Copy"); this.$message({message: &#39;复制成功&#39;,type: &#39;success&#39;});oInput.remove()
},