Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.1k views
in Technique[技术] by (71.8m points)

document.execCommand("copy"),怎么在页面加载完毕之后自动执行

document.execCommand("copy"),点击之后调用返回true,页面加载完成之后调用返回的是false,怎么可以在页面加载完成之后,复制 文本


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
这里有一个复制文本的dom
<template>
    <div>
        <span id="bar">需要复制的文本</span>
        <button class="btn" data-clipboard-target="#bar">点击复制文本</button>
    </div>
</template>
<script>
import ClipboardJS from 'clipboard'

export default {
    mounted () {
        this.clip = new ClipboardJS('.btn')
        this.clip.on('success', () => {
          alert('复制成功')
        })
        this.clip.on('error', (e) => {
          console.error(e)
          alert('复制失败,请重试')
        })
        this.$once('hook:beforeDestroy', () => {
            this.clip && this.clip.destroy()
        })
    }
}
</script>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...