Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.2k 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 Reply

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...