今天小編給大家分享一下Vue全局水印如何實(shí)現(xiàn)的相關(guān)知識(shí)點(diǎn),內(nèi)容詳細(xì),邏輯清晰,相信大部分人都還太了解這方面的知識(shí),所以分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后有所收獲,下面我們一起來(lái)了解一下吧。
成都創(chuàng)新互聯(lián)專注于靈壽企業(yè)網(wǎng)站建設(shè),成都響應(yīng)式網(wǎng)站建設(shè)公司,成都商城網(wǎng)站開發(fā)。靈壽網(wǎng)站建設(shè)公司,為靈壽等地區(qū)提供建站服務(wù)。全流程定制制作,專業(yè)設(shè)計(jì),全程項(xiàng)目跟蹤,成都創(chuàng)新互聯(lián)專業(yè)和態(tài)度為您提供的服務(wù)
【需求】系統(tǒng)內(nèi)頁(yè)面顯示水印,登錄頁(yè)面沒有水?。ㄍ顺龅卿洉r(shí),登錄頁(yè)面不會(huì)顯示水印)
/* * @Author: 劉小二 * @Date: 2021-07-15 14:43:27 * @LastEditTime: 2021-07-15 15:00:27 * @LastEditors: Please set LastEditors * @Description: 添加水印 * @FilePath: /huashijc_MeetingSys/src/common/warterMark.js */ "use strict" let watermark = {} let setWatermark = (str) => { let id = "1.23452384164.123412415" if (document.getElementById(id) !== null) { document.body.removeChild(document.getElementById(id)) } let can = document.createElement("canvas") can.width = 250 can.height = 120 let cans = can.getContext("2d") cans.rotate(-15 * Math.PI / 150) cans.font = "20px Vedana" cans.fillStyle = "rgba(200, 200, 200, 0.20)" cans.textAlign = "left" cans.textBaseline = "Middle" cans.fillText(str, can.width / 8, can.height / 2) let div = document.createElement("div") div.id = id div.style.pointerEvents = "none" div.style.top = "35px" div.style.left = "0px" div.style.position = "fixed" div.style.zIndex = "100000" div.style.width = document.documentElement.clientWidth + "px" div.style.height = document.documentElement.clientHeight + "px" div.style.background = "url(" + can.toDataURL("image/png") + ") left top repeat" document.body.appendChild(div) return id } // 該方法只允許調(diào)用一次 watermark.set = (str) => { let id = setWatermark(str) setInterval(() => { if (document.getElementById(id) === null) { id = setWatermark(str) } }, 500) window.onresize = () => { setWatermark(str) } } const outWatermark = (id) => { if (document.getElementById(id) !== null) { const div = document.getElementById(id) div.style.display = "none" } } watermark.out = () => { const str = "1.23452384164.123412415" outWatermark(str) } export default watermark
// 1.在App.vue文件中,導(dǎo)入該文件 import Watemark from "@/common/watermark"; computed: { userName() { const name = this.$store.state.user.name return (name && name.length > 0) ? name : "未獲取到用戶名" } }, mounted() { Watermark.set(this.userName) } // 2.在其他頁(yè)面引用 import Watemark from "@/common/watermark"; created() { Watermark.set("admin") }
const outWatermark = (id) => { if (document.getElementById(id) !== null) { const div = document.getElementById(id) div.style.display = "none" } } router.afterEach((to) => { if(to.path == "/"){ Watermark.out() // 清除水印 }else{ Watermark.set("未獲取到用戶名") // 設(shè)置水印title } });
以上就是“Vue全局水印如何實(shí)現(xiàn)”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家閱讀完這篇文章都有很大的收獲,小編每天都會(huì)為大家更新不同的知識(shí),如果還想學(xué)習(xí)更多的知識(shí),請(qǐng)關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。