对于新手们来说,如何写一个可以多用的组件,还是有点难度的,组件如何重用,如何传值这些在实际使用中,是多少会存在一些障碍的,所以今天特意写一个最常用的模态框组件提供给大家,希望能帮助到您!
懒癌患者直接复制粘贴即可
Modal.vue组件
<template>
<!-- 过渡动画 -->
<transition name="modal-fade">
<!-- 关闭模态框事件 和 控制模态框是否显示 -->
<div class="modal-backdrop" @click="$emit('closeModal')" v-show="show">
<div class="modal">
<img class="img" :src="/UploadFiles/2021-04-02/imgadress">
新建一个index.js文件,在其中全局引入组件,全局引入之后,就不用在每个调用的组件里面单独引入了,可以直接使用
import Modalfrom "./Modal.vue";
const components = {
install: function (Vue) {
Vue.component('Modal', Modal);
}
}
//导出组件
export default components;
Index.vue中调用
<template>
<div class="index">
<!-- 提交成功模态框 -->
<Modal
ref="Modal"
:imgadress="imgadress"
v-show="isModalVisible"
statusText="提交成功"
@closeModal="closeModal"
contentText="Index.vue"
:IDList="IDList"
:buttonBackground="red"
sure="确定"
@confirm="confirm"
>
<!-- :payMoney="payMoney"
yuan="元" -->
</Modal>
<button @click="showModel">支付成功模态框</button>
</div>
</template>
<script>
export default {
name: 'Index',
data(){
return{
// 模态框
imgadress:require('./../../assets/img/success.png'),
isModalVisible:false,
show: false,
showToast: false,
thisIndex:0,
green:'green',
blue:'',
red:'',
IDList:[
{payMoney:23456,yuan:'、'},
{payMoney:23456,yuan:'、'},
{payMoney:23456,yuan:'、'},
{payMoney:23456,yuan:'、'},
{payMoney:23456,yuan:'、'},
{payMoney:23456,yuan:'、'},
{payMoney:23456,yuan:'、'},
],
payMoney:99,
}
},
methods:{
// 提示模态框
showModel(){
this.isModalVisible = true;
this.blue = this.$refs.Model.blue
this.red = this.$refs.Model.red
},
closeModal(){
this.isModalVisible = false
},
confirm(){
console.log(11111111111);
},
}
}
</script>
效果如图
模态框-1.gif
如果只需要一个确定按钮,只需要在调用的时候,这么写就好了
<template>
<div class="index">
<!-- 提交成功模态框 -->
<Modal
ref="Modal"
:imgadress="imgadress"
v-show="isModalVisible"
statusText="提交成功"
@closeModal="closeModal"
contentText="Index.vue"
:IDList="IDList"
:buttonBackground="blue"
@button="closeModal"
sure="确定"
alert="1"
>
</Modal>
<button @click="showModel">支付成功模态框</button>
</div>
</template>
如图
模态框-2.gif
可能并不是特别完美,如果您发现有缺点,还请不吝赐教!
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
暂无“详解如何用VUE写一个多用模态框组件模版”评论...
更新动态
2025年11月07日
2025年11月07日
- 小骆驼-《草原狼2(蓝光CD)》[原抓WAV+CUE]
- 群星《欢迎来到我身边 电影原声专辑》[320K/MP3][105.02MB]
- 群星《欢迎来到我身边 电影原声专辑》[FLAC/分轨][480.9MB]
- 雷婷《梦里蓝天HQⅡ》 2023头版限量编号低速原抓[WAV+CUE][463M]
- 群星《2024好听新歌42》AI调整音效【WAV分轨】
- 王思雨-《思念陪着鸿雁飞》WAV
- 王思雨《喜马拉雅HQ》头版限量编号[WAV+CUE]
- 李健《无时无刻》[WAV+CUE][590M]
- 陈奕迅《酝酿》[WAV分轨][502M]
- 卓依婷《化蝶》2CD[WAV+CUE][1.1G]
- 群星《吉他王(黑胶CD)》[WAV+CUE]
- 齐秦《穿乐(穿越)》[WAV+CUE]
- 发烧珍品《数位CD音响测试-动向效果(九)》【WAV+CUE】
- 邝美云《邝美云精装歌集》[DSF][1.6G]
- 吕方《爱一回伤一回》[WAV+CUE][454M]

