当前位置:网站首页>Wechat applet_ 15. Pure data field
Wechat applet_ 15. Pure data field
2022-07-18 23:38:00 【icestone_ kai】
What is a pure data field :
Concept : Pure data fields are those that are not used for interface rendering data Field
Application scenarios :; For example, in some cases , some data The fields in will not be displayed on the interface , It will not be passed to other components , Use only inside the current component , With this characteristic data The field is suitable to be set as a pure data field
benefits : Pure data fields help improve the performance of page updates
Usage rule :
stay Component Constructor's options In nodes , Appoint pureDataPatten For a regular expression , Fields whose field names match this regular expression will become pure data fields , The sample code is as follows :
// components/numsAdd/numsAdd.js
Component({
options: {
// Specify all with _ The data field at the beginning is pure data field
pureDataPattern: /^_/
},
/** * The initial data of the component */
data: {
a:true,
_b:true,
}
}
Using pure data fields to transform data listeners :
Component({
options: {
// Specify all with _ The data field at the beginning is pure data field
pureDataPattern: /^_/
},
data: {
_rgb: {
r: 0,
g: 0,
b: 0,
},
fullColor: '0,0,0' // according to rgb Three properties of an object , Dynamic computing fullColor Value
},
})
Case complete code :
WXML:
<nums></nums>
Component's WXML:
<view class="randomColor" style="background-color: rgb({
{
fullColor}});"></view>
<text>
{
{rgb.r}},{
{rgb.g}},{
{rgb.b}}
At present RGB value :{
{fullColor}}
</text>
<button size="mini" type="primary" bindtap="rAdd">R+1</button>
<button size="mini" type="primary" bindtap="gAdd">G+1</button>
<button size="mini" type="primary" bindtap="bAdd">B+1</button>
Component's css:
.randomColor {
display: flex;
justify-content: center;
width: 100%;
height: 200rpx;
}
Component's .js:
// components/numsAdd/numsAdd.js
Component({
/** * A list of properties of a component */
properties: {
},
options: {
// Specify all with _ The data field at the beginning is pure data field
pureDataPattern: /^_/
},
/** * The initial data of the component */
data: {
_rgb: {
r: 0,
g: 0,
b: 0,
},
fullColor: '0,0,0' // according to rgb Three properties of an object , Dynamic computing fullColor Value
},
/** * A list of methods for a component */
methods: {
rAdd() {
this.setData({
'_rgb.r': this.data._rgb.r + 5 > 255 ? 255 : this.data._rgb.r + 5
})
},
gAdd() {
this.setData({
'_rgb.g': this.data._rgb.g + 5 > 255 ? 255 : this.data._rgb.g + 5
})
},
bAdd() {
this.setData({
'_rgb.b': this.data._rgb.b + 5 > 255 ? 255 : this.data._rgb.b + 5
})
},
},
// Data listening node
observers: {
'_rgb.**': function (obj) {
this.setData({
fullColor: `${
obj.r},${
obj.g},${
obj.b}`
})
}
// ' object . attribute A, object . attribute B':function( attribute A The new value of , attribute B The new value of ){}
// Object triggers this listener in three ways :
// [ For attributes A assignment ] Use setData Set up this.data. object . attribute A Trigger when
// [ For attributes B assignment ] Use setData Set up this.data. object . attribute B Trigger when
// [ Directly assign values to objects ] Use setData Set up this.data. object Trigger when
},
})
function , This part of the code is circled :
边栏推荐
- leetcode-两数之和
- 20220715 domestic CONDA does not FQ the method of installing the latest version of pytoch
- (pytorch advanced way II) transformer learning and difficult code implementation
- Summer study matlab notes
- 星巴克不使用两阶段提交
- canal-deployer canal-adapter镜像构建,部署
- Clean the disk with CMD command (mainly the system disk)
- Comparative investigation of three commonly used time series databases - incluxdb, Prometheus, iotdb
- ZVS电路初步测试
- 6. JVM generational model -- garbage collection in the old age
猜你喜欢

微信小程序_16,组件的生命周期

【开发教程1】开源蓝牙心率防水运动手环-套件检测教程

星巴克不使用两阶段提交
![[decision tree] use decision tree to diagnose breast cancer](/img/aa/ef3468f99d02845f3fd0414931073f.png)
[decision tree] use decision tree to diagnose breast cancer

在代码中用YYYY-MM-DD要注意了!

Guangzhou cavalry domineering "Princess hug", full of security!

ADB common entry instructions
![[technology fragment] rename suffix of duplicate files based on exponential diffusion binary search](/img/1c/19fe2d9df5e075b903058aa0b9b521.png)
[technology fragment] rename suffix of duplicate files based on exponential diffusion binary search

ASP. Net printing industry printing management system, source code free sharing

5.< tag-动态规划和完全背包问题>lt.70. 爬楼梯 || 进阶版 + lt.322. 零钱兑换 + lt.139. 单词拆分 + lt.279.完全平方数 dbc
随机推荐
[development tutorial 3] crazy shell arm function mobile phone - Introduction to the whole board resources
What are the efficient test methods for app regression testing?
Leetcode sum of two numbers
Mysql存储模型
leetcode-两数相加
Mysql索引的使用
Multithreaded application
ADB common entry instructions
Preliminary test of ZVS circuit
广州铁骑霸气“公主抱”,安全感拉满!
Hibench generates benchmark data sets [wordcount as an example]
剑指 Offer II 119. 最长连续序列
(pytorch advanced road III) conv2d
二叉樹心得
Reflection and experience on problems in performance testing
绝地求生 吃鸡 98k 不自动关镜子
Offer gifts in July. Buy a cloud plate and give it to the super grade Guiqi. It's only limited to 2 months. If you want to buy it, hurry up
Summary of this week 2
nodejs 定义错误验证机制
验证两个字符串一致