1. Use of uni.showModal
uni.showModal({
title:'',
content:'',
success(res){
if(res.confirm){
console.log('点击确定按钮')
} else if(res.cancel){
console.log('点击取消按钮')
}
}
})
scenes to be used:
The pop-up box can choose to confirm or cancel
Select OK to execute the required code in res.confirm,
Select Cancel to cancel the current operation.
2. The usefulness of #ifdef #ifndef #endif in uniapp (conditional compilation)
Role: processing compatible multi-terminal platform
#ifdef |
Only available on a certain platform |
#ifndef |
Use on other platforms besides this platform (not used by this platform) |
#endif |
end conditional compilation |
%PLATFORM% |
The platform that needs to be compiled, the above MP is the meaning of each small program |
The meaning of the platform logo
logo |
platform |
APP-PLUS |
5+App |
MP |
WeChat Mini Program/Alipay Mini Program/Baidu Mini Program/Toutiao Mini Program/QQ Mini Program |
MP-WEIXIN |
WeChat applet |
MP-ALIPAY |
Alipay applet |
MP-BAIDU |
Baidu applet |
MP-TOUTIAO |
Toutiao Mini Program |
MP-QQ |
QQ applet |
H5 |
H5 |
APP-PLUS-NVUE |
5+App nvue |
Example: A certain piece of code compiled only on the WeChat applet
// #ifdef MP-WEIXIN
代码内容
// #endif
Conditional compilation is implemented using comments. Comments are written differently in different grammars. JavaScript uses //comments, CSS uses /**/
Appears only under App
// #ifdef APP-PLUS
代码内容
// #endif
Will not appear on the H5 platform
// #ifndef H5
代码内容
// #endif
In addition to supporting conditional compilation of a single platform, it also supports simultaneous compilation of multiple platforms, using || (or) to separate the platform name,
Will appear on App and H5 platform
// #ifdef APP-PLUS || H5
代码内容
// #endif