定义一个按钮
<a-button style="margin-left: 16px" type="primary" @click="handleGenerateLink">
<img src="../../assets/imgs/linkIcon.png" alt="" style="margin: -3px 8px 0 0">
生成链接
<div
id="generatelink"
:name="urls"
value="生成链接"
style="display: none"
>
生成链接
</div>
</a-button>
方法
const { origin } = window.location
const { pathname } = window.location
// 生成链接
const handleGenerateLink = () => {
// 获取 token
urls.value = `${origin + pathname}#/dataReport/${taskId}?token=1111`
showModalGenerateLink.value = true
const clipBoardContent=document.getElementById('generatelink').attributes.name.value
const oInput = document.createElement('input')
oInput.value = clipBoardContent
document.body.appendChild(oInput)
oInput.select()
document.execCommand('Copy')
oInput.style.display = 'none'