Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the methods of passing values of WeChat Mini Programs parameters?

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article introduces the relevant knowledge of "what are the methods of passing values of WeChat Mini Programs parameters?". In the operation of actual cases, many people will encounter such a dilemma. Then let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

One: the method of passing the value of parameters

1: data-id

We can add a data-* attribute to the HTML element to pass the value we need, using the method description:

(1) set data-id

(2): take value + transfer value

PlayTap:function (e) {const dataset = e.currentTarget.dataset; wx.navigateTo ({url:'.. / play/index?id='+ dataset.id}) console.log (dataset.id);}

(3): value

OnLoad:function (param) {/ / Page initialization this.setData ({currentId:param.id})}

Data- Note: data- names cannot have uppercase letters. Once I found this error only after looking for a capital letter for a long time. Objects cannot be stored in the data-* attribute.

2: set the method ID of id to pass the value

Instructions on how to use:

(1) set id

(2) take a value

Get the value of the set id through e.currentTarget.id, and then pass the value by setting the global object

3: add parameters to navigator and pass values

Instructions on how to use

(1) pass value: concatenate? id (parameter name) = the value to be passed after the attribute url of navigator (if multiple parameters are separated by & name=value&... (.)

(2) value:

OnLoad (params) {app.fetch (API.detail + params.id, (err,data) = > {})}

Second: data request encapsulation

1. Put all interfaces in a unified js file and export

Const api = {interface1: 'https://........', interface2:' https://.......', interface3: 'https://....',.} module.exports = api

2: create a method to encapsulate request data in app.js

Fetch (url,data, callback) {wx.request ({url,data: data, header: {'Content-Type':' application/json'}, success (res) {callback (null, res.data);}, fail (e) {callback (e);}})}

3: call the encapsulated method to request data in the child page

Import API from ".. / api/api.js"; const app = getApp (); const conf = {data: {title:' is desperately loading.', loadding:true}, onLoad () {app.fetch (API.hot, {}, (err,data) = > {})}

Three: use the template (found that the template is really a good thing!)

1: define template: name of name setting template

2: use templates

First introduce the template

Then write the name.. of the template after using the template is It needs to be data through data.

Four: the properties and methods that Array is easy to use.

The Array.isArray () method is used to determine whether a value is Array. If so, true is returned, otherwise false is returned.

The concat () method merges the array or non-array values passed in with the original array to form a new array and returns.

The forEach () method executes the provided function (callback function) once for each element of the array.

The join () method concatenates all the elements in the array into a string.

The keys () method returns an iterator of an array index.

The map () method returns a new array of values returned after each element in the original array calls a specified method.

The pop () method deletes the last element in an array and returns that element.

The push () method adds one or more elements to the end of the array and returns the new length of the array (the length attribute value).

ToString () returns a string representing the specified array and its elements.

Five: common methods of object Object

1 initialization method

Var obj = []; var obj = new obj (); var obj = Object.create (null)

2 methods of adding elements

Dic ["key"] = "value"

3 the method of deleting key

Delete dic ["key"]

4 clear all entries of words

Dic.clear ()

5 Delete

Delete dic

6 ways to view all properties

Object.keys (obj)

All the key names of the object are strings, so it is OK to add quotation marks or not. if the key name is a numeric value, it will be automatically converted to a string, but if the key name does not meet the conditions of the identification name (for example, the first character is a number, or contains spaces or operators), you must put quotation marks, otherwise an error will be reported.

7 read attributes

Obj.name | | obj ['name']

Note: numeric key names cannot use dot operators (because they will be treated as decimal points), only square brackets operators can be used.

8 check whether the variable is declared

If (obj.name) | | if (obj ['name'])

The 9 in operator is used to check whether the object contains a property, and returns true if it does, false otherwise

If ('x' in obj) {return 1}

10 for... In cycle

Used to traverse all the properties of an object

For (var i in obj) {console.log (obj);}

11 with statement

Function: provide some writing convenience when manipulating multiple properties of the same object

With (obj) {name1 = 1name2 = 2;}

Equivalent to

Obj.name1 = 1 obj. Name 2 = 2; "what are the methods of passing values for WeChat Mini Programs parameters?" this is the end of the introduction. Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report