当前位置:网站首页>Condition annotation in uni-app realizes cross segment compatibility, navigation jump and parameter transfer, component creation and use, and life cycle function
Condition annotation in uni-app realizes cross segment compatibility, navigation jump and parameter transfer, component creation and use, and life cycle function
2022-07-03 06:23:00 【Sunshine Youth ~】
One 、UNI-APP Realize cross segment compatibility through conditional annotation
1、 The parameters corresponding to the corresponding platform in the condition annotation
① platform :5+APP value :APP-PLUS
② platform :H5 value :H5
③ platform : Wechat applet value :MP-WEIXIN
④ platform : Alipay applet value :MP-ALIPAY
⑤ platform : Baidu applet value :MP-BAIDU
⑥ platform : Headline widget value :MP-BAIDU
⑦ platform :QQ Applet value :MP-QQ At present, only cli Support
⑧ platform : Wechat applet / Alipay applet / Baidu applet / Headline widget /QQ Applet value :MP
2、 How to write it : With #ifdef Add platform logo <!-- #ifdef H5 --> start , With #endif ending <!-- #endif -->
<!-- #ifdef H5 -->
<view> I just hope that in H5 The page shows </view>
<!-- #endif -->
<!-- #ifdef MP-WEIXIN -->
<view> I just want to display in the wechat applet page </view>
<!-- #endif -->
/* H5 Style in */
/* #ifdef H5 */
view {
color: hotpink;
}
/* #endif */
/* Style in wechat applet */
/* #ifdef MP-WEIXIN */
view {
color: blue;
}
/* #endif */
Two 、UNI-APP In two ways Navigation jump and The ginseng
1、 Declarative navigation
(1)、 You can return to the previous page after jumping The ginseng ?id=88 ?id=88&age=19 Pass multiple parameters
<navigator url="/pages/detail/detail?id=88&age=19"> Go to the details page </navigator>
(2)、 The previous page was unloaded after jump open-type="switchTab"
<navigator url="/pages/message/message" open-type="switchTab"> switchTab Jump to the information page </navigator>
(3)、 The previous page was unloaded after jump open-type="redirect"
<navigator url="/pages/detail/detail" open-type="redirect"> redirect Go to the details page </navigator>
2、 Programming navigation
(1)、 Set the jump button
<button @click="goDetail"> Go to the details page </button>
<button @click="goMessage"> Jump to the information page </button>
<button type="primary" @click="redirectDetail"> Jump to the information page and close the current page </button>
(2)、 Corresponding jump function
methods: {
// Go to the details page
goDetail() {
uni.navigateTo({
url:"/pages/detail/detail"
})
},
// Jump to the information page , The previous page is unloaded after jump
goMessage() {
uni.switchTab({
url:"/pages/message/message"
})
},
redirectDetail() {
uni.redirectTo({
url:"/pages/detail/detail"
})
}
}
3、 The ginseng
(1)、 Set the corresponding transfer parameters ?id=88 For transmitting multiple parameters & Connect ?id=88&age=19
<navigator url="/pages/detail/detail?id=88&age=19"> Go to the details page </navigator>
(2)、 Accept the passed parameters on the details page
// Accept the parameters
onLoad(options) {
console.log(options)
},
3、 ... and 、 Component's Create and use components Life cycle function
1、 So let's create one Components test, stay index Write in page test Components
<test v-if="flag"></test>
// stay test Code in the component page
(1)、 Called after instance initialization beforeCreate
// Called after instance initialization beforeCreate
beforeCreate() {
console.log(' The instance is called after initialization ')
console.log(this.num)
},
(2)、 Called immediately after the instance is created created It is mainly used to initialize some data
//
// Called immediately after the instance is created created It is mainly used to initialize some data
created() {
console.log(' The instance is called immediately after it is created ')
console.log(this.num)
this.intId = setInterval(()=>{
console.log(' Execution timer ')
},1000)
},
(3)、 Called before the mount begins beforeMount
// Called before the mount begins beforeMount
beforeMount() {
console.log('beforemount Called before the mount begins ',document.getElementById('myView'))
// console.log(this.num)
},
(4)、 When mounted to an instance, it is called mounted operation DOM
// When mounted to an instance, it is called mounted operation DOM
mounted() {
console.log('mounted When mounted to an instance, it is called ',document.getElementById('myView'))
},
(5)、 When the component is destroyed, execute
// When the component is destroyed, execute
destroyed() {
console.log(' Component destroyed ')
// clear
clearInterval(this.intId)
}
(6)、 Set a button to reverse
checkTest() {
// Take the opposite
this.flag = !this.flag
}
边栏推荐
- Shell conditional statement
- Phpstudy setting items can be accessed by other computers on the LAN
- Zhiniu stock project -- 05
- 【C#/VB.NET】 将PDF转为SVG/Image, SVG/Image转PDF
- Page text acquisition
- Exportation et importation de tables de bibliothèque avec binaires MySQL
- Use selenium to climb the annual box office of Yien
- 有意思的鼠标指针交互探究
- 【LeetCode】Day93-两个数组的交集 II
- Project summary --01 (addition, deletion, modification and query of interfaces; use of multithreading)
猜你喜欢

技术管理进阶——你了解成长的全貌吗?

CKA certification notes - CKA certification experience post

从小数据量分库分表 MySQL 合并迁移数据到 TiDB

Cesium 点击获取模型表面经纬度高程坐标(三维坐标)

Push box games C #

Click cesium to obtain three-dimensional coordinates (longitude, latitude and elevation)

ThreadLocal的简单理解

Kubernetes notes (III) controller

Selenium - 改变窗口大小,不同机型呈现的宽高长度会不一样

有意思的鼠标指针交互探究
随机推荐
Project summary --01 (addition, deletion, modification and query of interfaces; use of multithreading)
Page text acquisition
方差迭代公式推导
Kubesphere - build MySQL master-slave replication structure
项目总结--2(Jsoup的基本使用)
Selenium ide installation recording and local project maintenance
【C#/VB.NET】 将PDF转为SVG/Image, SVG/Image转PDF
轻松上手Fluentd,结合 Rainbond 插件市场,日志收集更快捷
表达式的动态解析和计算,Flee用起来真香
Oauth2.0 - using JWT to replace token and JWT content enhancement
ROS+Pytorch的联合使用示例(语义分割)
有意思的鼠標指針交互探究
Pdf files can only print out the first page
MySQL带二进制的库表导出导入
Characteristics and isolation level of database
Kubernetes notes (VIII) kubernetes security
23 design models
PHP用ENV获取文件参数的时候拿到的是字符串
SQL实现将多行记录合并成一行
Mysql5.7 group by error