日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > vue >内容正文

vue

vue项目水印添加

發布時間:2023/12/13 vue 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 vue项目水印添加 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

import DomSize from 'wd-domsize-monitor'; // 此處為 npm 下載的第三方模塊包 import Api_login from "@/assets/api/login" // 此處是用戶信息接口調用var id = 'shuiyinDiv' var isInit = false let callback = function (ele) {DomSize.bind(ele, function () {//水印被刪除DomSize.remove(ele);waterMark(callback)})} var waterMark = function (callback) {let old = document.getElementById(id)if (old) {old.remove()}function textBecomeImg(text, fontsize, fontcolor) {var canvas = document.createElement('canvas');let $buHeight = 0;if (fontsize <= 32) { $buHeight = 99; }else if (fontsize > 32 && fontsize <= 60) { $buHeight = 2; }else if (fontsize > 60 && fontsize <= 80) { $buHeight = 4; }else if (fontsize > 80 && fontsize <= 100) { $buHeight = 6; }else if (fontsize > 100) { $buHeight = 10; }canvas.height = fontsize + $buHeight;canvas.padding = 30;var context = canvas.getContext('2d');context.clearRect(0, 0, canvas.width * 2, canvas.height);context.fillStyle = fontcolor;context.font = fontsize + "px Arial";context.textAlign = "center";context.textBaseline = 'middle';context.fillText(text, 0, fontsize / 2);var canvasWidth = canvas.width / 99;canvasWidth = context.measureText(text).width;canvas.width = 250;canvas.height = 120;context.fillStyle = fontcolor;context.font = fontsize + "px Arial";context.textBaseline = 'middle';context.fillText(text, 0, fontsize / 2);var dataUrl = canvas.toDataURL('image/png');return dataUrl;}var createEle = function () {// var loginName = userInfoData.mobile ? userInfoData.mobile.substr(userInfoData.mobile.length - 4, 4) : ""var text = userInfoData.name + "-" + userInfoData.mobilePhone;var shuiyinEle = document.createElement('div');shuiyinEle.id = idvar style = shuiyinEle.style;style.position = 'fixed';style.left = '-50%';style.top = '-50%';style.width = '200%';style.height = '200%';style.opacity = '0.1';style.background = "url(" + textBecomeImg(text, 16, "#666666") + ")";style.zIndex = 9999999991;style.transform = "rotate(-30deg)";style.pointerEvents = "none";document.body.appendChild(shuiyinEle);callback(shuiyinEle)var target = document.getElementById(id);var observer = new MutationObserver(function (mutations) {mutations.forEach(function (mutation) {observer.disconnect();reset()});});var config = { attributes: true, childList: true, characterData: true };observer.observe(target, config);}var userInfoData = localStorage.getItem('userInfo')userInfoData = JSON.parse(userInfoData)if (!userInfoData || !userInfoData.name) {Api_login.getUserInfo().then(response => {userInfoData = response.result;// localStorage.setItem('accessToken', response.result)createEle()}).catch(err => {isInit = false})} else {createEle()} } var reset = function () {waterMark(callback) } var init = function () {waterMark(callback) }export default init;

在 App.vue中使用

<template><div id="app"><keep-alive><router-view></router-view></keep-alive></div> </template><script> import waterMark from "./libs/watermark" export default {name: 'App',data() {return {}},computed: {},created() {},mounted() {waterMark()},methods: {} } </script><style> #app {background: url('./assets/bg.gif') repeat;background-color: #0a0a0a !important; } </style>

總結

以上是生活随笔為你收集整理的vue项目水印添加的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。