vue實(shí)現(xiàn)點(diǎn)擊復(fù)制到粘貼板
本文實(shí)例為大家分享了vue實(shí)現(xiàn)點(diǎn)擊復(fù)制到粘貼板的具體代碼,供大家參考,具體內(nèi)容如下
背景: 業(yè)務(wù)開發(fā)中遇到,點(diǎn)擊復(fù)制內(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: '復(fù)制成功', ? ? ? ? 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="請(qǐng)輸入內(nèi)容" ? ? ? ? /> ? ? ? </el-col> ? ? ? <el-col :span="2"> ? ? ? ? <el-tooltip class="item" effect="dark" content="復(fù)制" 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: '測(cè)試內(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: '復(fù)制成功', ? ? ? ? type: 'success' ? ? ? }) ? ? ? oInput.remove() ? ? } ? } } </script> <style lang="scss"> .primary-icon { ? cursor: pointer; ? color: #409eff; ? margin-left: 10px; } </style>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Vue ECharts直角坐標(biāo)系配置詳細(xì)講解
數(shù)據(jù)的重要性我們大家都知道,就算再小的項(xiàng)目中都可能使用幾個(gè)圖表展示,我最近在做項(xiàng)目的過程中也是需要用到圖表,最后選擇了echarts圖表庫(kù)2022-12-12vue使用Print.js打印頁(yè)面樣式不出現(xiàn)的解決
這篇文章主要介紹了vue使用Print.js打印頁(yè)面樣式不出現(xiàn)的解決,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-10-10基于Vue中使用節(jié)流Lodash throttle詳解
今天小編就為大家分享一篇基于Vue中使用節(jié)流Lodash throttle詳解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2019-10-10如何在vue3中使用滑塊檢驗(yàn)vue-puzzle-verification
這篇文章主要介紹了在vue3中使用滑塊檢驗(yàn)vue-puzzle-verification的相關(guān)資料,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧2023-11-11