What is mini program data-
Data- in mini program is a custom attribute.
The so-called data- is actually the data- prefix plus a custom attribute name. Data can be stored using such a structure. Using data- can solve the current situation of chaotic and unmanaged custom attributes.
dataset
Data can be defined in the component, which will be passed to SERVICE through events. Writing method: Start with data-, multiple words are linked by hyphens -, and cannot contain uppercase letters (uppercase letters will be automatically converted to lowercase letters) such as data-element-type. Finally, hyphens will be converted to camel case in event.currentTarget.dataset elementType.
Example:
<view data-alpha-beta="1" data-alphaBeta="2" bindtap="bindViewTap"> DataSet Test </view>
js code:
Page({ bindViewTap:function(event){ event.currentTarget.dataset.alphaBeta === 1 // - 会转为驼峰写法 event.currentTarget.dataset.alphabeta === 2 // 大写会转为小写 } })
PHP Chinese website, a large number of free small program development tutorials, welcome to learn!
The above is the detailed content of Mini program data-what is it?. For more information, please follow other related articles on the PHP Chinese website!