Vue uses custom instructions to add watermarks to the bottom of the page

Vue uses custom instructions to add watermarks to the bottom of the page

Project Scenario

Add a custom watermark to the entire background of the project. You can change the watermark text, font color, etc.

Implementation ideas

  • The technology used here is mainly canvas. In the process of realizing watermarking, the characteristics of canvas are mainly used.
  • Use the canvas feature to generate a base64 image file, and then set its font size, color, etc.
  • Finally, set it as the background image, which realizes the watermark effect of the page

Achieve results

Implementation Code

<template>
  <div class="water-marker" >
      <div v-waterMarker="{text:'Carlo vest - All rights reserved',textColor:'rgba(180, 180, 180, 0.4)'}">
        <div class="water-marker-item">Testing problem, testing problem, testing problem, testing problem, testing problem, testing problem</div>
      </div>
  </div>
</template>

<script>
import waterMarker from '../../directive/test/waterMarker'
export default {
  directives: {
    waterMarker
  },
  data(){
    return {
    }
  },
  methods:{
  }
}
</script>

<style lang="scss">
.water-marker{
  height: 300px;
  .water-marker-item{
    line-height: 300px;
  }
}
</style>

The waterMarker.js file is as follows:

function addWaterMarker(str, parentNode, font, textColor) {
  // Watermark text, parent element, font, text color var can = document.createElement('canvas')
  parentNode.appendChild(can)
  can.width = 200
  can.height = 150
  can.style.display = 'none'
  var cans = can.getContext('2d')
  cans.rotate((-20 * Math.PI) / 180)
  cans.font = font || '16px Microsoft JhengHei'
  cans.fillStyle = textColor || 'rgba(180, 180, 180, 0.3)'
  cans.textAlign = 'left'
  cans.textBaseline = 'Middle'
  cans.fillText(str, can.width / 10, can.height / 2)
  parentNode.style.backgroundImage = 'url(' + can.toDataURL('image/png') + ')'
}

const waterMarker = {
  bind: function (el, binding) {
    addWaterMarker(binding.value.text, el, binding.value.font, binding.value.textColor)
  },
}

export default waterMarker

This is the end of this article about how to use custom instructions in Vue to add a watermark at the bottom of the page. For more relevant content about adding a watermark at the bottom of the Vue page, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • The vue project realizes drawing a watermark in a certain area
  • Vue easily realizes watermark effect
  • Vue's global watermark implementation example
  • Vue integrates PDF.js to implement PDF preview and add watermark steps
  • Vue example code using class to create and clear watermark
  • How to use pictures and picture watermarks with hidden text information in Vue
  • Vue implements page watermark function
  • Vue implements adding watermark effect to the page

<<:  Example of using CASE WHEN in MySQL sorting

>>:  VSCode+CMake+Clang+GCC environment construction tutorial under win10

Recommend

Detailed installation and use of docker-compose

Docker Compose is a Docker tool for defining and ...

Centos6.9 installation Mysql5.7.18 step record

Installation sequence rpm -ivh mysql-community-co...

vue-admin-template dynamic routing implementation example

Provide login and obtain user information data in...

Detailed explanation of Nginx forwarding socket port configuration

Common scenarios for Nginx forwarding socket port...

Detailed explanation of Django+Vue+Docker to build an interface testing platform

1. Two words at the beginning Hello everyone, my ...

Zabbix configures DingTalk's alarm function with pictures

Implementation ideas: First of all, the alarm inf...

Install MySQL5.5 database in CentOS7 environment

Table of contents 1. Check whether MySQL has been...

How to change the tomcat port number in Linux

I have several tomcats here. If I use them at the...

Analysis of rel attribute in HTML

.y { background: url(//img.jbzj.com/images/o_y.pn...

Solve the problem that await does not work in forEach

1. Introduction A few days ago, I encountered a p...

Detailed explanation of Nginx timeout configuration

I recently used nginx in a project, and used Java...

Example of nginx ip blacklist dynamic ban

When a website is maliciously requested, blacklis...

Implementing license plate input function in WeChat applet

Table of contents Preface background Big guess Fi...