在實時監(jiān)聽網(wǎng)絡(luò)狀態(tài)的時候我們切換頁面經(jīng)常會用到此場景
1.首先在uni-app項目中的App.vue文件中添加以下代碼
注意:監(jiān)聽頁面跳轉(zhuǎn)變化要寫在onLaunch方法里面
//注意要寫在App.vue文件的onLauch方法里面
onLaunch: function() {
//監(jiān)聽頁面跳轉(zhuǎn)變化
let that = this;
uni.addInterceptor('navigateTo', { //監(jiān)聽跳轉(zhuǎn)
success(e) {
that.watchRouter();
}
})
uni.addInterceptor('redirectTo', { //監(jiān)聽關(guān)閉本頁面跳轉(zhuǎn)
success(e) {
that.watchRouter();
}
})
uni.addInterceptor('switchTab', { //監(jiān)聽tabBar跳轉(zhuǎn)
success(e) {
that.watchRouter();
}
})
uni.addInterceptor('navigateBack', { //監(jiān)聽返回
success(e) {
that.watchRouter();
}
})
}
methods: {
watchRouter(){
console.log('路由進(jìn)行跳轉(zhuǎn)');
},
}
2.實現(xiàn)效果
? ? ? ? 每次切換頁面的時候都會執(zhí)行調(diào)用watchRouter函數(shù)里面的方法文章來源:http://www.zghlxwxcb.cn/news/detail-605722.html

?文章來源地址http://www.zghlxwxcb.cn/news/detail-605722.html
到了這里,關(guān)于uniapp切換路由監(jiān)聽導(dǎo)航跳轉(zhuǎn)(在監(jiān)聽網(wǎng)絡(luò)狀態(tài)時非常常用)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!