您好,登錄后才能下訂單哦!
今天小編給大家分享一下vue怎么實現(xiàn)點擊復制到粘貼板的相關(guān)知識點,內(nèi)容詳細,邏輯清晰,相信大部分人都還太了解這方面的知識,所以分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后有所收獲,下面我們一起來了解一下吧。
效果:
關(guān)鍵代碼:
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="請輸入內(nèi)容" /> </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: '測試內(nèi)容' } }, 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怎么實現(xiàn)點擊復制到粘貼板”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家閱讀完這篇文章都有很大的收獲,小編每天都會為大家更新不同的知識,如果還想學習更多的知識,請關(guān)注億速云行業(yè)資訊頻道。
免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。