The learning time is not short. Today, the company will not work overtime to summarize my development experience. The following is a summary that I think is very important! I wrote it down so that I can remember it more clearly. At the same time, I hope it can help those in need. Classmate
1: Parameter value transfer method
1: data-id
We can add data-* attributes to HTML elements to pass what we need Value, usage instructions:
(1) Set data-id
(2): Get value + pass value
playTap:function(e) {
const dataset = e.currentTarget.dataset;
wx .navigateTo({
.
}
(3): Value
onLoad:function (param) {
//Page initialization
This. setData({
) :data-* names cannot have capital letters. Once I found this error after searching for a long time because of a capital letter. Objects cannot be stored in data-* attributes
2: Settings Use the method identifier of id to pass the valueInstructions for use:(1)Set idGet the value of the set id through e.currentTarget.id, and then pass the value by setting the global object
3: Add parameter value transfer in navigator
Usage instructions
app.fetch(API.detail + params.id,(err,data) => {
})
}
},
success(res) { callback(null, res.data);
callback(e); ##import API from "../../api/api.js";
const app = getApp();
const conf = {
data :{
title:'Loading...',
loading:true
},
onLoad (){
app.fetch(API.hot,{},(err,data) => {
})
},
3: Use template ( I found that templates are such a good thing!)
1: Define template: name Set the name of the template
Define template
2: Use template
First introduce the template
Then use template is and then write the name of the template.. through data The transmission needs to be data
Four: Array’s easier-to-use attributes and methods
Array.isArray() method is used to determine whether a value is an Array. If so, return true, otherwise return false.
concat() method combines the incoming array or non-array value with the original array to form a new array and returns it.
forEach() method pairs the array The provided function (callback function) is executed once for each element.
join() method joins all elements in the array into a string.
keys() method returns an iterator of array indexes.
map() method returns a new array consisting of the return value of each element in the original array after calling a specified method
pop() method deletes one The last element in the array and returns this element.
push() method adds one or more elements to the end of the array and returns the new length of the array (length attribute value).
toString() returns a string representing the specified array and its elements.
5: Common methods of Object
1 Initialization method
var obj = [];
var obj = new obj();
var obj = Object.create(null);
2 How to add an element
dic[“key”] = “value”;
3 How to delete a key
delete dic[“key”];
4 Clear all entries of the word
dic.clear();
5 Delete
delete dic;
6 Method to view all attributes
Object.keys(obj);
All key names of the object are strings, so they cannot be added You can add quotes. If the key name is a numerical value, it will be automatically converted into a string. However, 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), it is not a number. You must add quotation marks, otherwise an error will be reported
6 Read attribute
obj.name || obj['name']
Note: Numeric key name The dot operator cannot be used (because it will be treated as a decimal point), only the square bracket operator can be used.
7 Check whether the variable is declared
if(obj.name) || if(obj['name'])
8 The in operator is used to check Whether the object contains a certain attribute, if so it returns true, otherwise it returns false
if ('x' in obj) {return 1}
9 for … in loop
Used to traverse all properties of an object
for (var i in obj) {
console.log(obj);
}
10 with statement
Function: Provide some writing convenience when operating multiple properties of the same object
with(obj) {
name1 = 1;
name2 = 2;
}
is equivalent to
obj.name1 = 1;
obj .name2 = 2;
The above is the detailed content of Summary of WeChat Mini Program Development Experience. For more information, please follow other related articles on the PHP Chinese website!