当前位置:网站首页>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
}
边栏推荐
- Derivation of variance iteration formula
- Printer related problem record
- Kubernetes notes (I) kubernetes cluster architecture
- Zhiniu stock -- 03
- [set theory] relational closure (relational closure solution | relational graph closure | relational matrix closure | closure operation and relational properties | closure compound operation)
- 致即将毕业大学生的一封信
- 【5G NR】UE注册流程
- SSH link remote server and local display of remote graphical interface
- Use selenium to climb the annual box office of Yien
- Mysql database
猜你喜欢

GPS坐标转百度地图坐标的方法

YOLOV3学习笔记

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

有意思的鼠標指針交互探究

Kubesphere - set up redis cluster

Chapter 8. MapReduce production experience
![[set theory] relational closure (relational closure solution | relational graph closure | relational matrix closure | closure operation and relational properties | closure compound operation)](/img/a4/00aca72b268f77fe4fb24ac06289f5.jpg)
[set theory] relational closure (relational closure solution | relational graph closure | relational matrix closure | closure operation and relational properties | closure compound operation)

Merge and migrate data from small data volume, sub database and sub table Mysql to tidb

Cesium Click to obtain the longitude and latitude elevation coordinates (3D coordinates) of the model surface

Project summary --01 (addition, deletion, modification and query of interfaces; use of multithreading)
随机推荐
Oauth2.0 - using JWT to replace token and JWT content enhancement
In depth analysis of kubernetes controller runtime
When PHP uses env to obtain file parameters, it gets strings
Luogu problem list: [mathematics 1] basic mathematics problems
Leetcode problem solving summary, constantly updating!
The most classic 100 sentences in the world famous works
Kubernetes notes (VII) kuberetes scheduling
UNI-APP中条件注释 实现跨段兼容、导航跳转 和 传参、组件创建使用和生命周期函数
【5G NR】UE注册流程
Kubernetes notes (III) controller
数值法求解最优控制问题(一)——梯度法
学习笔记 -- k-d tree 和 ikd-Tree 原理及对比
Use abp Zero builds a third-party login module (I): Principles
10万奖金被瓜分,快来认识这位上榜者里的“乘风破浪的姐姐”
【LeetCode】Day93-两个数组的交集 II
About the difference between count (1), count (*), and count (column name)
pytorch练习小项目
Method of converting GPS coordinates to Baidu map coordinates
Important knowledge points of redis
技术管理进阶——你了解成长的全貌吗?