创建config/index.js
const config ={
tabList : ['/TabPage/index/index','/TabPage/shop/shop','/TabPage/food/food','/TabPage/User/index'], // TabBar路径
baseUrl:'', //api基本路径
shareTitle:'', //默认分享标题
homePath:'/TabPage/index/index' //主页路径
}
module.exports = config
在main.js中引入config
注意在// #ifndef VUE3和// #endif
// 路由跳转
Vue.prototype.$JumpTo = (e,type = 'navigate') =>{
if (typeof e === 'number') {
uni.navigateBack({
delta: e
})
} else if (typeof e === 'string') {
if (config.tabList.some(item => item === e)) {
uni.switchTab({
url: e
})
} else {
if (type === 'navigate') {
uni.navigateTo({
url: e
})
} else {
uni.redirectTo({
url: e
})
}
}
}
}
uniapp页面内使用方式
<view class="AddCard" @tap="$JumpTo(`/<你要去往的路径>`)">添加银行卡 +</view>
输入数字就是返回上级,输入1返回上一级,输入2返回上两级,以此类推