页面代码
<template>
<view class="wrap">
<button @click="onClick">按钮</button>
<input type="text" placeholder="请输入" />
<actionsheet v-model="showSheet"></actionsheet>
</view>
</template>
<script setup>
import { ref } from 'vue';
const showSheet = ref(false);
const onClick = () => {
showSheet.value = true;
};
</script>
<style lang="scss" scoped>
.wrap {
padding-top: 200rpx;
}
</style>
自定义弹窗代码
<template>
<view :class="classes.root" v-if="modelValue">
<view :class="classes.wrap">
<input :class="classes.input" type="text" placeholder="请输入" />
</view>
</view>
</template>
<script setup>
import { createNamespace } from '@/utils';
const { bem } = createNamespace('actionsheet');
const classes = reactive({
root: computed(() => [bem()]),
wrap: computed(() => [bem('wrap', { bottom: type.value === 'bottom', center: type.value === 'center' })]),
input: computed(() => [bem('input')])
});
const props = defineProps({
modelValue: Boolean,
type: {
type: String,
default: 'bottom'
}
});
const { modelValue, type } = toRefs(props);
const emits = defineEmits(['update:modelValue']);
watch(modelValue, (newVal, oldVal) => {});
</script>
<style lang="scss" scoped>
.mini-actionsheet {
position: fixed;
inset: 0;
background-color: rgba(0, 0, 0, 0.6);
&__wrap {
background-color: #fff;
height: 400rpx;
&--bottom {
position: absolute;
left: 0;
right: 0;
bottom: 0;
}
}
&__input {
border: 1px solid red;
z-index: 999;
}
}
</style>