js复制文本插件Clipboard

高恺
2023-12-01
 <button
        class="copy-btn cobyOrderSn"
        data-clipboard-action="copy"
        :data-clipboard-text="`www.baidu.com\n密码:n123456`"
        @click="handleCopy"
      >复制链接</button>
  // 复制
    handleCopy() {
      const _this = this
      const clipboard = new Clipboard('.cobyOrderSn')
      clipboard.on('success', function () {
        _this.$message({
          message: '复制成功',
          type: 'success'
        })
        // 释放内存
        clipboard.destroy()
      })
      clipboard.on('error', function () {
        _this.$message('复制失败')
        // 释放内存
        clipboard.destroy()
      })
    }
 类似资料: