回到上一页代码uniapp中代码
<template>
<view class="my_footer">
<view class="m_goBack" @click.stop="handlergoBack()"></view>
<view class="m_index" @click.stop="handlergoIndex()"></view>
</view>
</template>
<script>
export default {
methods: {
//回到上一个页面
handlergoBack() {
//如果没有上一个页面 就回到首页
const pages = getCurrentPages();
if (pages.length === 2) {
uni.navigateBack({
delta: 1
});
} else if (pages.length === 1) {
uni.switchTab({
url: '/pages/index/index',
})
} else {
uni.navigateBack({
delta: 1
});
}
},
//回到首页
handlergoIndex(){
uni.switchTab({
url:'/pages/index/index'
})
}
}
}
</script>
<style lang="scss">
.my_footer {
background: #fff;
position: fixed;
bottom: 0;
left: 0;
width: 100%;
height: 96rpx;
display: flex;
justify-content: center;
align-items: center;
z-index: 88;
.m_index {
flex: 1;
height: 96rpx;
background: url('@/static/home.png') center no-repeat;
background-size: 32rpx 30rpx;
}
.m_goBack {
flex: 1;
width: 80rpx;
height: 96rpx;
background: url('@/static/back.png') center no-repeat;
background-size: 20rpx 32rpx;
}
}
</style>