Vue之全局水印的實(shí)現(xiàn)示例
【需求】系統(tǒng)內(nèi)頁(yè)面顯示水印,登錄頁(yè)面沒(méi)有水印(退出登錄時(shí),登錄頁(yè)面不會(huì)顯示水印)
1.創(chuàng)建水印Js文件
/* * @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
2.引入操作
2.1 在App.vue中引用或其他頁(yè)面
// 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') }
2.2 在router配置文件中引用
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 } });
到此這篇關(guān)于Vue之全局水印的實(shí)現(xiàn)示例的文章就介紹到這了,更多相關(guān)Vue 全局水印內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- Vue實(shí)現(xiàn)頁(yè)面添加水印功能
- vue實(shí)現(xiàn)頁(yè)面添加水印效果
- Vue 集成 PDF.js 實(shí)現(xiàn) PDF 預(yù)覽和添加水印的步驟
- vue輕松實(shí)現(xiàn)水印效果
- vue中使用帶隱藏文本信息的圖片、圖片水印的方法
- vue實(shí)現(xiàn)上傳圖片添加水印
- vue實(shí)現(xiàn)上傳圖片添加水印(升級(jí)版)
- vue項(xiàng)目實(shí)現(xiàn)對(duì)某個(gè)區(qū)域繪制水印
- Vue使用自定義指令實(shí)現(xiàn)頁(yè)面底部加水印
- vue實(shí)現(xiàn)頁(yè)面添加水印
相關(guān)文章
關(guān)于vue屬性使用和不使用冒號(hào)的區(qū)別說(shuō)明
這篇文章主要介紹了關(guān)于vue屬性使用和不使用冒號(hào)的區(qū)別說(shuō)明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-10-10實(shí)時(shí)通信Socket?io的使用示例詳解
這篇文章主要為大家介紹了實(shí)時(shí)通信Socket?io的使用示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-11-11vue中el-tree動(dòng)態(tài)初始默認(rèn)選中和全選實(shí)現(xiàn)方法
這篇文章主要給大家介紹了關(guān)于vue中el-tree動(dòng)態(tài)初始默認(rèn)選中和全選實(shí)現(xiàn)的相關(guān)資料,eltree默認(rèn)選中eltree是一種常用的樹形控件,通常用于在網(wǎng)頁(yè)上呈現(xiàn)樹形結(jié)構(gòu)的數(shù)據(jù),例如文件夾、目錄、組織結(jié)構(gòu)等,需要的朋友可以參考下2023-09-09詳解Vue3.0中ElementPlus<input輸入框自動(dòng)獲取焦點(diǎn)>
這篇文章主要給大家介紹了關(guān)于Vue3.0中ElementPlus<input輸入框自動(dòng)獲取焦點(diǎn)>的相關(guān)資料,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用vue3.0具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2023-04-04