https://www.npmjs.com/package/watermark-domhttps://github.com/saucxs/watermark-dom<template> <!-- App.vue 文件--> <div id="app"> <router-view /> </div> </template> <script> // 安装文件,如果安装报错,可以用cnpm // npm install watermark-dom --save // npm install js-cookie --save import watermark from 'watermark-dom' import Cookies from 'js-cookie' export default { name: "App", mounted(){ setTimeout(()=>{ // 在登录文件中,登录成功后,记得将用户名存到本地cookie中 // Cookies.set('username',username); // 获取cookie中的username添加水印 let username = Cookies.get('username'); if(username){ let now = new Date(); let year = now.getFullYear(); let month = now.getMonth()+1; let day = now.getDate(); month = month<10?'0'+month:month; day = day<10?'0'+day:day; let date = year+'-'+month+'-'+day; watermark.load({ watermark_txt: username+','+date }) } },1000) } }; </script>