新建Model.vue
<template>
<div v-if="show">
<div class="modal-mask">
<div class="modal-wrapper">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">{
{ title }}</h5>
<button
type="button"
class="btn-close"
data-bs-dismiss="modal"
aria-label="Close"
@click="$emit('hide')"
></button>
</div>
<div class="modal-body">
<slot />
</div>
</div>
</div>
</div>
</div>
</div>
</template>
<script setup>
defineProps({
title: {
type: String,
required: true,
},
show: {
type: Boolean,
default: false,
},
});
</script>
<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;
}
</style>
全局使用
import { createApp } from 'vue'
import App from './App.vue'
import icons from './components/icons/all'
import Modal from './components/Model.vue'
const app=createApp(App)
// app.component("icon-upload",IconUpload) //注册全局组件
for(const[ key,value] of Object.entries(icons)){
app.component(key,value)
}//注册全局组件
app.component("app-modal",Modal);
app.mount('#app')
ActionBar.vue 添加点击emit
<template>
<div class="d-flex
justify-content-between
align-items-center
border-bottom
pt-2
pb-3">
<button class="btn btn-outline-primary">
<icon-upload />上传
</button>
<div class="action-buttons" v-show="selectedItems.length">
<button type="button" class="rounded-button" title="Rename" @click="$emit('rename')" v-show="selectedItems.length===1">