效果展示:

 

直接上代码: 

<template>
    <view>
        <unidrawer ref="draw" :mask="mask" :width="drawWid" :mode='mode' >
            <view style="padding:30rpx;">
                <view class="uni-title">抽屉式导航</view>
            </view>
            <button type="warn" @tap="hide()" style="margin-top: 100rpx;">关闭</button>
        </unidrawer>
        <button type="primary" @tap="show()">显示</button>
    </view>
</template>
<script>
    import unidrawer from "@/uni_modules/uni-drawer/components/uni-drawer/uni-drawer.vue"
	const res = wx.getSystemInfoSync();
	const statusHeight = res.statusBarHeight; //状态栏高度
	const cusnavbarheight = (statusHeight + 44) + "px";
    export default {
        components: {unidrawer},
        data() {
            return {
                mask: true,
                left:'left',
                drawWid:'50%',//需要把uni-drawer组件里的参数width的type改为String,我这里是第63 64行
                maskClick:true,
                mode:'left'
            };
        },
        methods: {
            //显示抽屉
            show(){
                this.$refs.draw.open();
            },
            hide(){
                this.$refs.draw.close();
            }
        }
    }
</script>

<style scoped lang="scss">
  ::v-deep .uni-drawer {
    margin-top: v-bind(cusnavbarheight)
  }
</style>
Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐