vue 點擊復制當前網址


template 部分

<div  class="NewNoticeDetails-ctrlButton" @click="copy()">
                    <button class="NewNoticeDetails-ctrlButton">復制鏈接</button>
                </div>
 
data部分
//獲取當前網站的網址
            windowUrl : window.location.href,
 
methods方法
//點擊復制的方法
        copy(){
            var domUrl = document.createElement("input");
            domUrl.value = this.windowUrl;
            domUrl.id = "creatDom";
            document.body.appendChild(domUrl);
            domUrl.select(); // 選擇對象
            document.execCommand("Copy"); // 執行瀏覽器復制命令
            let creatDom = document.getElementById("creatDom");
            creatDom.parentNode.removeChild(creatDom);
            this.$message({
                message: '復制成功',
                type: 'success'
            });
        },


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM