Vue3+Antd實(shí)現(xiàn)彈框顯示內(nèi)容并加入復(fù)制按鈕
使用Vue3+antd實(shí)現(xiàn)點(diǎn)擊彈框出現(xiàn)內(nèi)容并可復(fù)制內(nèi)容的功能:
HTML部分:
<a-button type="primary" @click="showModel"> 打開彈框 </a-button> <!-- @ok 是彈框中確定按鈕的操作,@cancel 是彈框中取消按鈕的操作 --> <a-modal title="內(nèi)容如下" :visible="isModalVisible" @ok="handleOk" @cancel="handleCancel" > <div style="display: flex; flex-direction: column; align-items: center;"> <p>彈框內(nèi)容</p> <a-button type="primary" @click="copyContent">復(fù)制</a-button> </div> </a-modal>
JS部分:
import {message} from "ant-design-vue"; const isModalVisible = ref(false) // 打開彈框 const showModel = () => { isModalVisible.value = true } // 彈框中取消按鈕 const handleCancel = () => { isModalVisible.value = false; } // 彈框中復(fù)制按鈕 const copyContent = () => { const textToCopy = '彈框內(nèi)容'; // 彈框內(nèi)容,即<p>中的內(nèi)容 navigator.clipboard.writeText(textToCopy).then(() => { message.success("復(fù)制成功") console.log('Text copied to clipboard'); }).catch((err) => { message.warning("復(fù)制失敗") console.error('Unable to copy text to clipboard', err); }); } // 彈框中確定按鈕 const handleOk = () => { isModalVisible.value = false; };
以上代碼彈框是有兩個(gè)按鈕:取消、確認(rèn)。
如何實(shí)現(xiàn)只有一個(gè)取消/確認(rèn)按鈕
新增::footer="null" 即可取消掉兩個(gè)按鈕,但是要手動(dòng)加入按鈕:
<a-modal title="內(nèi)容如下" :visible="isModalVisible" :footer="null" > <div style="display: flex; flex-direction: column; align-items: center;"> <p>彈框內(nèi)容</p> <a-button type="primary" @click="copyContent">復(fù)制</a-button> </div> <div align="right"> <a-button type="default" align="right" @click="handleCancel">取消</a-button> </div> </a-modal>
修改確認(rèn)/取消按鈕位置樣式等
<a-button type="primary" @click="showModel"> 打開彈框 </a-button> <!-- @ok 是彈框中確定按鈕的操作,@cancel 是彈框中取消按鈕的操作 --> <a-modal title="內(nèi)容如下" :visible="isModalVisible" @ok="handleOk" @cancel="handleCancel" > <template #okText> 修改'確認(rèn)'按鈕中的文本 </template> <template #cancelText> 修改'取消'按鈕中的文本 </template> <template #footer> 自定義按鈕位置樣式等 </template> <template #closeIcon> 修改彈框右上角'x'的樣式 </template> <div style="display: flex; flex-direction: column; align-items: center;"> <p>彈框內(nèi)容</p> <a-button type="primary" @click="copyContent">復(fù)制</a-button> </div> </a-modal>
到此這篇關(guān)于Vue3+Antd實(shí)現(xiàn)彈框顯示內(nèi)容并加入復(fù)制按鈕的文章就介紹到這了,更多相關(guān)Vue3 Antd彈框內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Vue3獲取DOM節(jié)點(diǎn)的3種方式實(shí)例
Vue本來(lái)無(wú)需操作DOM來(lái)更新界面,而且Vue也不推薦我們直接操作DOM,但是我們非要拿到DOM操作DOM怎么辦,下面這篇文章主要給大家介紹了關(guān)于Vue3獲取DOM節(jié)點(diǎn)的3種方式,需要的朋友可以參考下2023-02-02Vite打包優(yōu)化之縮小打包體積實(shí)現(xiàn)詳解
這篇文章主要為大家介紹了使用Vite縮小打包體積如何實(shí)現(xiàn)的示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-01-0115分鐘學(xué)會(huì)vue項(xiàng)目改造成SSR(小白教程)
這篇文章主要介紹了15分鐘學(xué)會(huì)vue項(xiàng)目改造成SSR(小白教程),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-12-12vue 監(jiān)聽是否切屏和開啟小窗的實(shí)現(xiàn)過(guò)程
這篇文章主要介紹了vue 監(jiān)聽是否切屏和開啟小窗的過(guò)程,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-04-04Vite打包性能優(yōu)化之開啟Gzip壓縮實(shí)踐過(guò)程
vue前端項(xiàng)目發(fā)布的時(shí)候,打包可實(shí)現(xiàn)gzip格式的壓縮,下面這篇文章主要給大家介紹了關(guān)于Vite打包性能優(yōu)化之開啟Gzip壓縮的相關(guān)資料,需要的朋友可以參考下2022-12-12