<view class="water_top" style="pointer-events: none;"> <view class="water-text">{{watermarkText}}</view> <view class="water-text">{{watermarkText}}</view> <view class="water-text">{{watermarkText}}</view> <view class="water-text">{{watermarkText}}</view> <view class="water-text">{{watermarkText}}</view> <view class="water-text">{{watermarkText}}</view> <view class="water-text">{{watermarkText}}</view> <view class="water-text">{{watermarkText}}</view> <view class="water-text">{{watermarkText}}</view> </view>
.water_top{ position: fixed; top:0; bottom: 0; left: 0; right: 0; transform:rotate(-12deg); /** 旋转 可自己调整 **/ z-index: 9999; } .water-text{ float: left; width:375rpx; color: rgba(169,169,169,.2); text-align: center; font-size: 95%; margin: 100rpx 0; /** 间距 可自调 **/ }
// components/watermark/watermark.js Component({ /** * 组件的属性列表 */ properties: { name:String }, /** * 组件的初始数据 */ data: { watermarkText:'闽达钢铁' }, /** * 组件生命周期声明对象,组件的生命周期 * :created、attached、ready、moved、detached * 将收归到 lifetimes 字段内进行声明 * 原有声明方式仍旧有效,如同时存在两种声明方式 * 则 lifetimes 字段内声明方式优先级最高 */ lifetimes:{ attached(){ this.setData({ watermarkText:this.data.watermarkText + this.properties.name }) } }, /** * 组件的方法列表 */ methods: { } })
{ "pages":[ "pages/index/index", "pages/logs/logs" ], "window":{ "backgroundTextStyle":"light", "navigationBarBackgroundColor": "#fff", "navigationBarTitleText": "Weixin", "navigationBarTextStyle":"black" }, "style": "v2", "sitemapLocation": "sitemap.json", /* 引入 tips:删除引入注释 放入代码会报错 */ "usingComponents": { "watermark":"/components/watermark/watermark" } }
<!-- 放入顶部即可 --> <watermark name="班长"></watermark>
<!--logs.wxml--> <watermark name="张大梅"></watermark> <view class="container log-list"> <block wx:for="{{logs}}" wx:key="timeStamp" wx:for-item="log"> <text class="log-item">{{index + 1}}. {{log.date}}</text> </block> </view>
https://git.weixin.qq.com/depressiom/demo.git