当前位置:网站首页>UNI-APP中条件注释 实现跨段兼容、导航跳转 和 传参、组件创建使用和生命周期函数
UNI-APP中条件注释 实现跨段兼容、导航跳转 和 传参、组件创建使用和生命周期函数
2022-07-03 06:13:00 【阳光少年~】
一、UNI-APP中条件注释实现跨段兼容
1、条件注释中相应平台所对应的参数
①平台:5+APP 值:APP-PLUS
②平台:H5 值:H5
③平台:微信小程序 值:MP-WEIXIN
④平台:支付宝小程序 值:MP-ALIPAY
⑤平台:百度小程序 值:MP-BAIDU
⑥平台:头条小程序 值:MP-BAIDU
⑦平台:QQ小程序 值:MP-QQ 目前仅cli支持
⑧平台:微信小程序/支付宝小程序/百度小程序/头条小程序/QQ小程序 值:MP
2、写法:以 #ifdef
加平台标识<!-- #ifdef H5 -->
开头,以 #endif
结尾 <!-- #endif -->
<!-- #ifdef H5 -->
<view>我只希望在H5页面中显示</view>
<!-- #endif -->
<!-- #ifdef MP-WEIXIN -->
<view>我只希望在微信小程序页面中显示</view>
<!-- #endif -->
/* H5中的样式 */
/* #ifdef H5 */
view {
color: hotpink;
}
/* #endif */
/* 微信小程序中的样式 */
/* #ifdef MP-WEIXIN */
view {
color: blue;
}
/* #endif */
二、UNI-APP中两种方式 导航跳转 和 传参
1、声明式导航
(1)、跳转后可以返回上一页面 传参 ?id=88 ?id=88&age=19
传多个参数
<navigator url="/pages/detail/detail?id=88&age=19"> 跳转至详情页</navigator>
(2)、跳转后上一页面被卸载了open-type="switchTab"
<navigator url="/pages/message/message" open-type="switchTab"> switchTab跳转至信息页</navigator>
(3)、跳转后上一页面被卸载了open-type="redirect"
<navigator url="/pages/detail/detail" open-type="redirect"> redirect跳转至详情页</navigator>
2、编程式导航
(1)、设置跳转按钮
<button @click="goDetail">跳转至详情页</button>
<button @click="goMessage">跳转至信息页</button>
<button type="primary" @click="redirectDetail">跳转至信息页并关闭当前页面</button>
(2)、对应的跳转函数
methods: {
// 跳转至详情页
goDetail() {
uni.navigateTo({
url:"/pages/detail/detail"
})
},
// 跳转至信息页,跳转后上一页面被卸载
goMessage() {
uni.switchTab({
url:"/pages/message/message"
})
},
redirectDetail() {
uni.redirectTo({
url:"/pages/detail/detail"
})
}
}
3、传参
(1)、设置相应的传参 ?id=88
传多个参数用&连接 ?id=88&age=19
<navigator url="/pages/detail/detail?id=88&age=19"> 跳转至详情页</navigator>
(2)、在详情页接受传过来的参数
// 接受传过来的参数
onLoad(options) {
console.log(options)
},
三、组件的 创建使用和组件的 生命周期函数
1、先创建一个 组件test
,在index
页面中写入 test
组件
<test v-if="flag"></test>
//在test组件页面中的代码
(1)、在实例初始化之后被调用 beforeCreate
// 在实例初始化之后被调用 beforeCreate
beforeCreate() {
console.log('实例初始化之后被调用')
console.log(this.num)
},
(2)、在实例创建完成后被立即调用 created
主要用于初始化一些数据
//
// 在实例创建完成后被立即调用 created 主要用于初始化一些数据
created() {
console.log('实例创建完成后被立即调用')
console.log(this.num)
this.intId = setInterval(()=>{
console.log('执行定时器')
},1000)
},
(3)、在挂载开始之前被调用 beforeMount
// 在挂载开始之前被调用 beforeMount
beforeMount() {
console.log('beforemount 在挂载开始之前被调用',document.getElementById('myView'))
// console.log(this.num)
},
(4)、挂载到实例上去之后调用 mounted
操作DOM
// 挂载到实例上去之后调用 mounted 操作DOM
mounted() {
console.log('mounted 挂载到实例上去之后调用',document.getElementById('myView'))
},
(5)、组件销毁了就执行
// 组件销毁了就执行
destroyed() {
console.log('组件销毁了')
// 清楚
clearInterval(this.intId)
}
(6)、设置一个按钮取反
checkTest() {
// 取反
this.flag = !this.flag
}
边栏推荐
猜你喜欢
23 design models
. Net program configuration file operation (INI, CFG, config)
Important knowledge points of redis
Core principles and source code analysis of disruptor
项目总结--01(接口的增删改查;多线程的使用)
Cesium 点击获取模型表面经纬度高程坐标(三维坐标)
Understand the first prediction stage of yolov1
SQL实现将多行记录合并成一行
有意思的鼠標指針交互探究
Kubernetes notes (VII) kuberetes scheduling
随机推荐
Introduction to software engineering
Support vector machine for machine learning
Kubernetes notes (VII) kuberetes scheduling
Kubernetes notes (III) controller
Une exploration intéressante de l'interaction souris - pointeur
Es remote cluster configuration and cross cluster search
Oauth2.0 - Introduction and use and explanation of authorization code mode
Cesium 点击获取模型表面经纬度高程坐标(三维坐标)
Kubernetes notes (VIII) kubernetes security
PMP notes
MySQL帶二進制的庫錶導出導入
BeanDefinitionRegistryPostProcessor
When PHP uses env to obtain file parameters, it gets strings
Alibaba cloud OOS file upload
Intel's new GPU patent shows that its graphics card products will use MCM Packaging Technology
Important knowledge points of redis
冒泡排序的简单理解
智牛股项目--04
Analysis of Clickhouse mergetree principle
In depth analysis of kubernetes controller runtime