Skip to content

Watermark 水印

介绍

在页面上添加特定的文字或图案作为水印,可用于防止信息盗用。

导入

js
import Watermark from '@/components/display/Watermark.vue'

使用方法

文字水印

通过 content 属性来设置水印的文字。

vue
<template>
  <view class="box">
    <Watermark content="NaEasy UI" />
  </view>
</template>

<style scoped>
.box {
  position: relative;
  width: 100%;
  height: 300px;
  background-color: #f5f5f5;
}
</style>

图片水印

通过 image 属性来设置水印图片,并使用 opacity 来调整水印的整体透明度。

vue
<template>
  <view class="box">
    <Watermark :image="WatermarkImage" :contentHeight="20" />
  </view>
</template>

<script setup>
import WatermarkImage from '../../static/watermark.png';
</script>

<style scoped>
.box {
  position: relative;
  width: 100%;
  height: 300px;
  background-color: #f5f5f5;
}
</style>

自定义间隔

通过 gapX 和 gapY 属性来设置水印之间的水平和垂直间隔。

vue
<template>
  <view class="box">
    <Watermark 
      :image="WatermarkImage" 
      :gapX="50"
      :gapY="50"
      :contentHeight="30"
    />
  </view>
</template>

<script setup>
import WatermarkImage from '../../static/watermark.png';
</script>

<style scoped>
.box {
  position: relative;
  width: 100%;
  height: 300px;
  background-color: #f5f5f5;
}
</style>

自定义倾斜角度

通过 rotate 属性来设置水印的倾斜角度(单位:度),默认值为-22。

vue
<template>
  <view class="box">
    <Watermark 
      :image="WatermarkImage" 
      :contentHeight="20"
      :rotate="25"
    />
  </view>
</template>

<script setup>
import WatermarkImage from '../../static/watermark.png';
</script>

<style scoped>
.box {
  position: relative;
  width: 100%;
  height: 300px;
  background-color: #f5f5f5;
}
</style>

全屏水印

通过 fullPage 属性设置水印为全屏显示。

vue
<template>
  <Watermark content="全屏水印" fullPage />
</template>

API 参考

Watermark

水印组件。

Props

名称说明类型必填默认值
width水印组件宽度。默认占满父容器number--
height水印组件高度。默认占满父容器number--
contentFont水印文字字体string-'14px Arial'
contentWidth水印文字宽度number-100
contentHeight水印文字高度number-60
offsetX水印文字水平间距(px)number-0
offsetY水印文字垂直间距(px)number-0
zIndex水印组件z-indexnumber | string-999
content水印内容string-''
contentColor水印字体颜色string-'text.second'
image水印图片string-''
rotate水印旋转角度(deg)number--22
fullPage水印组件是否全屏boolean-false
gapX水印组件水平间距(px)number-30
gapY水印组件垂直间距(px)number-40
opacity水印透明度number-0.4

Slots

名称说明
default默认插槽

Events

名称说明参数
无事件

主题变量

名称类型默认值说明
WatermarkContentFontstring'14px Arial'水印文字字体
WatermarkContentWidthnumber100水印文字宽度
WatermarkContentHeightnumber60水印文字高度
WatermarkRotatenumber-22水印旋转角度
WatermarkGapXnumber30水印组件水平间距
WatermarkGapYnumber40水印组件垂直间距
WatermarkTextColorstring'text.second'水印字体颜色
WatermarkOpacitynumber0.4水印透明度