帮我用vue3写一个点击出现底部弹框
时间: 2024-03-16 09:46:43 浏览: 85
好的,以下是一个简单的示例代码,可以实现在Vue3中点击按钮出现底部弹框:
template:
```html
<template>
<div>
<button @click="showModal = true">点击弹出底部弹框</button>
<transition name="modal">
<div class="modal-mask" v-if="showModal">
<div class="modal-wrapper">
<div class="modal-container">
<div class="modal-header">
<h3>底部弹框</h3>
<button class="modal-close" @click="showModal = false">×</button>
</div>
<div class="modal-body">
<p>这是一个底部弹框</p>
</div>
</div>
</div>
</div>
</transition>
</div>
</template>
```
script:
```javascript
<script>
import { defineComponent, ref } from 'vue';
export default defineComponent({
name: 'BottomModal',
setup() {
const showModal = ref(false);
return {
showModal,
};
},
});
</script>
```
style:
```css
<style scoped>
.modal-mask {
position: fixed;
z-index: 9998;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
display: table;
transition: opacity 0.3s ease;
}
.modal-wrapper {
display: table-cell;
vertical-align: middle;
}
.modal-container {
width: 300px;
margin: 0px auto;
padding: 20px 30px;
background-color: #fff;
border-radius: 2px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.33);
transition: all 0.3s ease;
font-family: Helvetica, Arial, sans-serif;
}
.modal-header h3 {
margin-top: 0;
color: #42b983;
}
.modal-body {
margin: 20px 0;
}
.modal-default-button {
float: right;
}
.modal-enter {
opacity: 0;
}
.modal-leave-active {
opacity: 0;
}
.modal-enter .modal-container,
.modal-leave-active .modal-container {
-webkit-transform: scale(1.1);
transform: scale(1.1);
}
</style>
```
以上代码中,我们使用了Vue3的Composition API,定义了一个showModal的状态,并在点击按钮时修改它的值,从而控制底部弹框的显示和隐藏。底部弹框使用了Vue3的过渡效果,实现了出现和隐藏的动画效果。注意,在实际使用中,您应该根据自己的实际需求进行调整和修改。
阅读全文