uniapp左滑导航
时间: 2023-08-18 13:07:37 浏览: 91
uniapp 自定义导航栏
回答: 在uniapp中实现左滑导航可以通过使用uni-drawer组件来实现。首先,你需要在uniapp官网下载并引入uni-drawer组件。然后,在你的代码中使用uni-drawer组件来创建一个左滑导航的抽屉。你可以在抽屉中添加需要的内容,比如导航链接。点击触发抽屉的按钮可以使用@click事件来调用showDrawer方法。另外,你还可以通过调节抽屉的宽度来调整抽屉的样式。最后,你可以在onNavigationBarButtonTap方法中来控制抽屉的打开和关闭状态。如果你想在app端实现返回键拦截事件,可以使用onBackPress方法来实现。
示例代码如下所示:
```
<template>
<view>
<view class="word-btn draw-cotrol-btn hideOnPc" @click="showDrawer('showLeft')">
<image src="../../static/daohang.png" class="img_logo2"></image>
</view>
<uni-drawer class="drawer" ref="showLeft" mode="left" :width="150" @change="change($event,'showLeft')">
<navigator url="demo" hover-class="navigator-hover">
<button type="default">联系我们</button>
</navigator>
<navigator url="ceshi" hover-class="navigator-hover">
<button type="default">测试</button>
</navigator>
</uni-drawer>
</view>
</template>
<script>
export default {
methods: {
showDrawer(e) {
this.$refs[e].open()
},
change(e, type) {
console.log((type === 'showLeft' ? '左窗口' : '右窗口') + (e ? '打开' : '关闭'))
this[type = e
},
onNavigationBarButtonTap(e) {
if (this.showLeft) {
this.$refs.showLeft.close()
} else {
this.$refs.showLeft.open()
}
},
onBackPress() {
if (this.showRight || this.showLeft) {
this.$refs.showLeft.close()
this.$refs.showRight.close()
return true
}
}
}
}
</script>
```
希望以上内容能帮助到你。如果还有其他问题,请随时提问。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* [uniapp左侧抽屉抽屉](https://blog.csdn.net/weixin_45098257/article/details/115717393)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"]
- *3* [uniapp上实现一个左滑显示删除按钮,右滑删除按钮消失](https://blog.csdn.net/py_boy/article/details/107101045)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文