Home  >  Article  >  WeChat Applet  >  Mini program data-what is it?

Mini program data-what is it?

angryTom
angryTomOriginal
2020-03-27 13:24:014243browse

Mini program data-what is it?

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn