国产99久久精品_欧美日本韩国一区二区_激情小说综合网_欧美一级二级视频_午夜av电影_日本久久精品视频

最新文章專題視頻專題問答1問答10問答100問答1000問答2000關鍵字專題1關鍵字專題50關鍵字專題500關鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關鍵字專題關鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
當前位置: 首頁 - 科技 - 知識百科 - 正文

詳解如何用VUE寫一個多用模態(tài)框組件模版

來源:懂視網 責編:小采 時間:2020-11-27 22:07:03
文檔

詳解如何用VUE寫一個多用模態(tài)框組件模版

詳解如何用VUE寫一個多用模態(tài)框組件模版:對于新手們來說,如何寫一個可以多用的組件,還是有點難度的,組件如何重用,如何傳值這些在實際使用中,是多少會存在一些障礙的,所以今天特意寫一個最常用的模態(tài)框組件提供給大家,希望能幫助到您! 懶癌患者直接復制粘貼即可 Modal.vue組件 <t
推薦度:
導讀詳解如何用VUE寫一個多用模態(tài)框組件模版:對于新手們來說,如何寫一個可以多用的組件,還是有點難度的,組件如何重用,如何傳值這些在實際使用中,是多少會存在一些障礙的,所以今天特意寫一個最常用的模態(tài)框組件提供給大家,希望能幫助到您! 懶癌患者直接復制粘貼即可 Modal.vue組件 <t

對于新手們來說,如何寫一個可以多用的組件,還是有點難度的,組件如何重用,如何傳值這些在實際使用中,是多少會存在一些障礙的,所以今天特意寫一個最常用的模態(tài)框組件提供給大家,希望能幫助到您!

懶癌患者直接復制粘貼即可

Modal.vue組件

<template>
 <!-- 過渡動畫 -->
 <transition name="modal-fade">
 <!-- 關閉模態(tài)框事件 和 控制模態(tài)框是否顯示 -->
 <div class="modal-backdrop" @click="$emit('closeModal')" v-show="show">
 <div class="modal">
 <img class="img" :src="imgadress" alt="">
 <div class="modal-body" id="modalDescription">
 <li></li>
 <!-- 狀態(tài)提示文字的插槽 -->
 <slot name="status">{{statusText}}</slot>
 <li></li>
 </div>
 <!-- 模態(tài)框內容文字 可有可無 -->
 <div class="modal-content" v-if="contentText">
 {{contentText}}
 <span v-if="IDList" v-for="item in IDList" :key="item.id">{{item.payMoney}}
 <i>{{item.yuan}}</i>
 </span>
 </div>
 <ul>
 <!-- 模態(tài)框按鈕 可選單個確定按鈕 和 兩個確定、取消按鈕 -->
 <!-- 單個確定按鈕 -->
 <li v-if="alert" :class="buttonBackground" @click.stop="$emit('button')">確定</li>
 <!-- 確定和取消按鈕 -->
 <li v-else class="confirm">
 <div>取消</div>
 <div :class="buttonBackground" @click.stop="$emit('confirm')">{{sure}}</div>
 </li>
 </ul>
 </div>
 </div>
 </transition>
</template>
<script>
export default {
 name:'modal',
 // 通過 props 傳值
 props: {
 imgadress:String,
 title:String, //標題文字
 show:{ //顯示取消
 type:Boolean,
 default:false
 },
 statusText:String, //狀態(tài)文字
 contentText:String, //描述文字
 IDList:Array, //ID 列表
 payMoney:Number,
 yuan:String,
 buttonBackground:String, //按鈕背景色
 alert:String, //判斷一個還是兩個按鈕
 sure:String, //第二個按鈕的提示文字
 
 },
 data(){
 return{
 closemodal:"close",
 // isModalVisible:false,
 // 確定和取消按鈕的兩種顏色
 red:'redBackground',
 blue:'blueBackground'
 }
 },
 methods:{
 // 關閉模態(tài)框事件
 close(){
 this.$emit('close')
 },
 }
}
</script>
<style lang="scss" scoped> 
.modal-backdrop {
 position: fixed; 
 top: 0; 
 right: 0; 
 bottom: 0; 
 left: 0; 
 background-color: rgba(0,0,0,.3); 
 display: flex; 
 justify-content: center; 
 align-items: center;
 z-index: 12;
 .modal { 
 background-color: #fff; 
 box-shadow: 2px 2px 20px 1px; 
 overflow-x:auto; 
 display: flex; 
 flex-direction: column; 
 width: 11.8rem;
 position: relative;
 border-radius: 0.2rem;
 .img{
 width: 3.6rem;
 height: 3.6rem;
 margin: 0.8rem 4.1rem;
 }
 .modal-header{ 
 padding: 0.6rem 4.1rem;
 width: 3.6rem;
 height: 3.6rem;
 box-sizing: border-box; 
 .img{
 width: 100%;
 height: 100%;
 }
 div{
 width: 100%;
 height: 100%;
 background: #000;
 }
 } 
 .modal-body{
 width: 100%;
 height: 0.48rem;
 padding: 0rem 1.6rem;
 margin-bottom: 0.8rem;
 box-sizing: border-box;
 display: flex;
 justify-content: space-between; 
 align-items: center; 
 li{
 width: 2rem;
 height: 0.04rem;
 background: #eeeee5;
 }
 }
 .modal-content{
 width: 100%;
 // height: 0.6rem;
 margin-bottom: 0.8rem;
 text-align: center;
 color: #34304B;
 span{
 color: #32B8B9;
 i{
 color: #4F4F4F;
 }
 }
 }
 ul{
 li{
 width: 100%;
 height: 1.52rem;
 line-height: 1.52rem;
 text-align: center;
 color: #fff;
 font-size: 0.56rem;
 letter-spacing: 0.4rem;
 }
 .confirm{
 display: flex;
 div:nth-child(1){
 flex: 1;
 background: #DEDEDE;
 color: #BCBBBF;
 }
 div:nth-child(2){
 flex: 1;
 color: #fff;
 }
 }
 }
 .blueBackground{
 background: #21A6DF;
 }
 .redBackground{
 background: #FF4046;
 }
 } 
}
/* 動畫 */
.modal-fade-enter,.modal-fade-leave-active{
 opacity: 0;
}
.modal-fade-enter-active, .modal-fade-leave-active{
 transition: opacity 0.5s ease;
}
</style>

新建一個index.js文件,在其中全局引入組件,全局引入之后,就不用在每個調用的組件里面單獨引入了,可以直接使用

import Modalfrom "./Modal.vue";
const components = {
 install: function (Vue) {
 Vue.component('Modal', Modal);
 }
}
//導出組件
export default components;

Index.vue中調用

<template>
 <div class="index">
<!-- 提交成功模態(tài)框 -->
 <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">支付成功模態(tài)框</button>

 </div>
</template>
<script>
export default {
 name: 'Index',
 data(){
 return{
 // 模態(tài)框
 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:{
 // 提示模態(tài)框
 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>

效果如圖

模態(tài)框-1.gif

如果只需要一個確定按鈕,只需要在調用的時候,這么寫就好了

<template>
 <div class="index">
<!-- 提交成功模態(tài)框 -->
 <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">支付成功模態(tài)框</button>

 </div>
</template>

如圖

模態(tài)框-2.gif

可能并不是特別完美,如果您發(fā)現有缺點,還請不吝賜教!

聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

文檔

詳解如何用VUE寫一個多用模態(tài)框組件模版

詳解如何用VUE寫一個多用模態(tài)框組件模版:對于新手們來說,如何寫一個可以多用的組件,還是有點難度的,組件如何重用,如何傳值這些在實際使用中,是多少會存在一些障礙的,所以今天特意寫一個最常用的模態(tài)框組件提供給大家,希望能幫助到您! 懶癌患者直接復制粘貼即可 Modal.vue組件 <t
推薦度:
標簽: VUE 模板 寫一個
  • 熱門焦點

最新推薦

猜你喜歡

熱門推薦

專題
Top
主站蜘蛛池模板: 亚洲三级电影网 | 精品国产一区二区三区久久久蜜臀 | 亚洲另类欧美日韩 | 看全色黄大色大片免费久久 | 亚洲 另类 在线 欧美 制服 | 在线播放精品一区二区啪视频 | 国产精品久久久久久久 | 国产成人精品免费大全 | 日韩综合图区 | 一区精品麻豆经典 | 91精品啪国产在线观看免费牛牛 | 免费一级淫片 | 日本高清天码一区在线播放 | 亚欧精品在线观看 | 欧美国产日韩一区二区三区 | 欧美国产日韩一区二区三区 | 91插插插插插 | 国产欧美日韩一区二区三区在线 | 国产成人精品视频 | 国产福利二区 | 黑丝草逼 | 欧美另类日韩中文色综合 | 亚洲欧美中文日韩在线 | 欧美日韩另类国产 | 美日韩三级 | 亚洲欧美另类日本 | 国产一区二区三区免费在线观看 | 国产不卡在线看 | 国产成人久久精品一区二区三区 | 国产成人一区二区三区 | 在线欧美v日韩v国产精品v | 日韩欧美大陆 | 国产精品久久亚洲一区二区 | 欧美日韩福利视频 | 国产一页 | 久久亚洲伊人中字综合精品 | 国产 欧美 日本 | 日韩欧美第一页 | 久久精品综合国产二区 | 日本一区二区三区免费看 | 国产成人精品一区二区免费视频 |