vue實現(xiàn)點擊復制到粘貼板
更新時間:2022年08月23日 11:02:49 作者:王博wangbo
這篇文章主要為大家詳細介紹了vue實現(xiàn)點擊復制到粘貼板,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了vue實現(xiàn)點擊復制到粘貼板的具體代碼,供大家參考,具體內容如下
背景: 業(yè)務開發(fā)中遇到,點擊復制內容到粘貼板的需求,記錄一下
效果:
關鍵代碼:
copyText() { ? ? ? const oInput = document.createElement('input') ? ? ? oInput.value = this.textarea ? ? ? document.body.appendChild(oInput) ? ? ? oInput.select() ? ? ? document.execCommand('Copy') ? ? ? this.$message({ ? ? ? ? message: '復制成功', ? ? ? ? type: 'success' ? ? ? }) ? ? ? oInput.remove() }
代碼: 以下是完整代碼
<template> ? <div class="white-body-view"> ? ? <el-row> ? ? ? <el-col :span="22"> ? ? ? ? <el-input ? ? ? ? ? v-model="textarea" ? ? ? ? ? type="textarea" ? ? ? ? ? resize="none" ? ? ? ? ? :rows="3" ? ? ? ? ? placeholder="請輸入內容" ? ? ? ? /> ? ? ? </el-col> ? ? ? <el-col :span="2"> ? ? ? ? <el-tooltip class="item" effect="dark" content="復制" placement="top"> ? ? ? ? ? <i class="el-icon-document-copy primary-icon" @click="copyText" /> ? ? ? ? </el-tooltip> ? ? ? </el-col> ? ? </el-row> ? </div> </template> <script> export default { ? data() { ? ? return { ? ? ? textarea: '測試內容' ? ? } ? }, ? methods: { ? ? copyText() { ? ? ? const oInput = document.createElement('input') ? ? ? oInput.value = this.textarea ? ? ? document.body.appendChild(oInput) ? ? ? oInput.select() ? ? ? document.execCommand('Copy') ? ? ? this.$message({ ? ? ? ? message: '復制成功', ? ? ? ? type: 'success' ? ? ? }) ? ? ? oInput.remove() ? ? } ? } } </script> <style lang="scss"> .primary-icon { ? cursor: pointer; ? color: #409eff; ? margin-left: 10px; } </style>
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
vue使用Print.js打印頁面樣式不出現(xiàn)的解決
這篇文章主要介紹了vue使用Print.js打印頁面樣式不出現(xiàn)的解決,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-10-10基于Vue中使用節(jié)流Lodash throttle詳解
今天小編就為大家分享一篇基于Vue中使用節(jié)流Lodash throttle詳解,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-10-10如何在vue3中使用滑塊檢驗vue-puzzle-verification
這篇文章主要介紹了在vue3中使用滑塊檢驗vue-puzzle-verification的相關資料,本文通過實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友參考下吧2023-11-11