vue实现点击复制功能

<template>
    <span v-for="(item, index) in codeList" :key="index" @click="copy(item)">{{
        item
    }}</span>
</template>

<script>
export default {
    data() {
        return {
            codeList: [
                '[资源名称]',
                '[服务名称]',
                '[告警时间]',
                '[告警对象]',
                '[告警指标]',
                '[告警值]',
                '[告警等级]',
                '[网络类别]',
                '[业务警种]',
                '[IP地址]'
            ]
        }
    },
    methods: {
        copy(item) {
            const input = document.createElement('input')
            document.body.appendChild(input)
            input.setAttribute('value', item)
            input.select()
            if (document.execCommand('copy')) {
                document.execCommand('copy')
                this.open2()
            }
            document.body.removeChild(input)
        },
        open2() {
            this.$message({
                message: '复制成功',
                type: 'success'
            })
        }
    }
}
</script>     
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。