提交 fb7daedc 编写于 作者: Q qiang

fix: 优化拦截器示例提示文案

上级 480fd1f5
<template> <template>
<view> <view>
<button @click="addInterceptor">添加拦截器</button> <button @click="addInterceptor">添加路由拦截器</button>
<button @click="removeInterceptor">移除拦截器</button> <button @click="removeInterceptor">移除路由拦截器</button>
<text>点击下方按钮{{msg}}</text>
<button @click="navigateTo">跳转到测试页面</button> <button @click="navigateTo">跳转到测试页面</button>
</view> </view>
</template> </template>
...@@ -9,7 +10,7 @@ ...@@ -9,7 +10,7 @@
<script> <script>
const interceptor = { const interceptor = {
invoke: function (options : NavigateToOptions) { invoke: function (options : NavigateToOptions) {
console.log('interceptor.invoke:', options) console.log('拦截 navigateTo 接口传入参数为:', options)
const url = './page2' const url = './page2'
uni.showToast({ uni.showToast({
title: `重定向到页面:${url}` title: `重定向到页面:${url}`
...@@ -17,16 +18,19 @@ ...@@ -17,16 +18,19 @@
options.url = url options.url = url
}, },
success: function (res : NavigateBackSuccess) { success: function (res : NavigateBackSuccess) {
console.log('interceptor.success:', res) console.log('拦截 navigateTo 接口 success 返回参数为:', res)
}, },
fail: function (err : NavigateToFail) { fail: function (err : NavigateToFail) {
console.log('interceptor.fail:', err) console.log('拦截 navigateTo 接口 fail 返回参数为:', err)
},
complete: function (res : NavigateToComplete) {
console.log('拦截 navigateTo 接口 complete 返回参数为:', res)
} }
} as Interceptor } as Interceptor
export default { export default {
data() { data() {
return { return {
msg: "会跳转到测试页面1"
} }
}, },
beforeUnmount() { beforeUnmount() {
...@@ -37,14 +41,16 @@ ...@@ -37,14 +41,16 @@
addInterceptor() { addInterceptor() {
uni.addInterceptor('navigateTo', interceptor) uni.addInterceptor('navigateTo', interceptor)
uni.showToast({ uni.showToast({
title: '拦截器已添加' title: '页面跳转已拦截'
}) })
this.msg = ",路由被劫持到测试页面2"
}, },
removeInterceptor() { removeInterceptor() {
uni.removeInterceptor('navigateTo', interceptor) uni.removeInterceptor('navigateTo', interceptor)
uni.showToast({ uni.showToast({
title: '拦截器已移除' title: '拦截器已移除'
}) })
this.msg = "会跳转到测试页面1"
}, },
navigateTo() { navigateTo() {
uni.navigateTo({ uni.navigateTo({
...@@ -54,6 +60,9 @@ ...@@ -54,6 +60,9 @@
}, },
fail(err) { fail(err) {
console.error('err:', err) console.error('err:', err)
},
complete(res) {
console.log('res:', res)
} }
}) })
} }
...@@ -63,4 +72,4 @@ ...@@ -63,4 +72,4 @@
<style> <style>
</style> </style>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册