Adaptive the RPX
RPX: the screen width can be adjusted to 750rpx.
RPX (Responsive Pixel) : ADAPTS to the screen width. Specify a screen width of 750rpx. For example, on iPhone6, the screen width is 375px and there are 750 physical pixels, then 750rpx = 375px = 750 physical pixels and 1rpx = 0.5px = 1 physical pixel.
RPX convert px (screen width / 750)
Convert PX to RPX (750 / screen width)
Designers can use 750px as the standard for visual artwork.
iPhone5 1rpx = 0.42px 1px = 2.34rpx
iPhone6 1rpx = 0.5px 1px = 2rpx
iPhone6 Plus 1rpx = 0.552px 1px = 1.81rpx
Copy the code
Array assignment
Tools is an array, array elements are objects, checked has to exist, index has to be of type number
var temp = "tools[" + index + "].checked";
this.setData({
[temp]: false
})
AverageVal = sum/(thicks.length) does not take effect
this.setData({
averageVal: (sum/len).toFixed(2)})Copy the code
Initialize the
self.setData({
tools: []})Copy the code
The whole assignment
ConfirmResult is an array of objectsthis.setData({
tools: confirmResult
})
Copy the code
Object assignment
ItemIndex can be a number or string
var temp = "requestStatus." + itemIndex
this.setData({
[temp]: {
status: false.checked: item.checked
}
})
Copy the code
Import an error
SaveToolNo is exports, import is bound to fail
module.exports.saveToolNo = saveToolNo; orexports.saveToolNo = saveToolNo;
import saveToolNo from '.. /equip/test.js'
Copy the code
When ‘.. The /tool/test.js’ file will report an error in the import file if it has no place to use it before entering this import page
var common = require('.. /tool/test.js')
common.saveToolNo();
Copy the code
Disable page scrolling
Method one:
Disablescroll: true Sets the page to be disabled
EnablePullDownRefresh: false
The disablescroll priority is smaller than enablePullDownRefresh
Method 2: Set the absolute position of the root element of the page
position: fixed;
top: 0;
bottom: 0;
left: 0;
right: 0;
Copy the code
Applets have no data binding
The applet has no data binding, uses Bindblur, updates the value
Copy the code
new Date()
The new Date() argument should be timestamp
Mobile test applet not supportednew Date("The 2021-02-07 14:34:03. 000 + 0800"But supportnew Date(1612679643000))
Copy the code
Solve callback hell
Togetcode, request1, and request2 all return new Promise
Such as
function loginToGetId(self) {
return new Promise((resolve, reject) = > {
tt.login({
success(res) {
resolve(res.code)
console.log('login Login succeeds${res.code}`);
},
fail(res) {
reject(res)
console.log('login call failed'); }})})}Copy the code
function request1(config, self) {
let {
url = ' ',
data = {},
method = 'GET',
base = ' '} = {... config}return new Promise((resolve, reject) = > {
tt.request({
url: base || BASE_URL + url,
method: method,
data: {... data},success: (res) = > {
// tt.hideLoading();
if(res.code) {
resolve(res.data)
} else {
resolve(res)
}
},
fail: (res) = > {
// tt.hideLoading();
reject(res)
},
})
}
Copy the code
function loginToGetUserInfo(self){
return new Promise((resolve, reject) = > {
loginToGetId(self).then((res) = >{
return request1(res, self);
}).then((res) = >{
return request2(res, self);
}).then((res) = >{
// console.log('login1 succeeded in obtaining user information :',res)
resolve(res)
}).catch((res) = >{
// console.log('login1 catch res:',res)
reject(res)
})
})
}
Copy the code
Input on the pit
The request interface in the onblur and onConfirm listener functions cannot pop up the soft keyboard
Disable scrolling on the page
Set in THE JSON of the page you want to set
"disableScroll": true
Copy the code
However, if input is set at the bottom of the page, the soft keyboard will not pop up
OnShow () and onLoad ()
The first time you open the applet and execute onLoad, the popup page will execute onShow