最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時間:2018年09月27日 13:40:14   作者:劉員外__  
這篇文章主要介紹了詳解如何用VUE寫一個多用模態(tài)框組件模版,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧

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

懶癌患者直接復(fù)制粘貼即可

Modal.vue組件

<template>
  <!-- 過渡動畫 -->
  <transition name="modal-fade">
    <!-- 關(guān)閉模態(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)框內(nè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, //標(biāo)題文字
    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:{
    // 關(guān)閉模態(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文件,在其中全局引入組件,全局引入之后,就不用在每個調(diào)用的組件里面單獨引入了,可以直接使用

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

Index.vue中調(diào)用

<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

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

<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ā)現(xiàn)有缺點,還請不吝賜教!

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • vue2+elementui進(jìn)行hover提示的使用

    vue2+elementui進(jìn)行hover提示的使用

    本文主要介紹了vue2+elementui進(jìn)行hover提示的使用,主要分為外部和內(nèi)部,具有一定的參考價值,感興趣的可以了解一下
    2021-11-11
  • Vue3菜單展開和收起實現(xiàn)

    Vue3菜單展開和收起實現(xiàn)

    在Vue項目中實現(xiàn)首頁布局,包括可收放的左側(cè)菜單和主體內(nèi)容區(qū),在store中管理菜單狀態(tài),通過修改isCollapse狀態(tài)控制菜單的展開與收起,在home.vue中編寫左側(cè)菜單欄的代碼和樣式,實現(xiàn)一個響應(yīng)式的用戶界面
    2024-09-09
  • Vue.js實現(xiàn)文件上傳和進(jìn)度條顯示功能

    Vue.js實現(xiàn)文件上傳和進(jìn)度條顯示功能

    在現(xiàn)代Web開發(fā)中,文件上傳是一個常見而重要的需求,無論是在用戶上傳頭像、文檔或者其他類型的文件時,良好的用戶體驗都是至關(guān)重要的,在這篇博客中,我們將介紹如何使用Vue.js來實現(xiàn)文件上傳功能,同時顯示上傳進(jìn)度條,需要的朋友可以參考下
    2024-11-11
  • vue 使用rules對表單字段進(jìn)行校驗的步驟

    vue 使用rules對表單字段進(jìn)行校驗的步驟

    這篇文章主要介紹了vue 使用rules對表單字段進(jìn)行校驗的步驟,幫助大家更好的理解和使用vue,感興趣的朋友可以了解下
    2020-12-12
  • vue element ui validate 主動觸發(fā)錯誤提示操作

    vue element ui validate 主動觸發(fā)錯誤提示操作

    這篇文章主要介紹了vue element ui validate 主動觸發(fā)錯誤提示操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-09-09
  • vue 2 實現(xiàn)自定義組件一到多個v-model雙向數(shù)據(jù)綁定的方法(最新推薦)

    vue 2 實現(xiàn)自定義組件一到多個v-model雙向數(shù)據(jù)綁定的方法(最新推薦)

    有時候我們需要對一個組件綁定自定義 v-model,以更方便地實現(xiàn)雙向數(shù)據(jù),例如自定義表單輸入控件,這篇文章主要介紹了vue 2 實現(xiàn)自定義組件一到多個v-model雙向數(shù)據(jù)綁定的方法,需要的朋友可以參考下
    2024-07-07
  • Vue循環(huán)中多個input綁定指定v-model實例

    Vue循環(huán)中多個input綁定指定v-model實例

    這篇文章主要介紹了Vue循環(huán)中多個input綁定指定v-model實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-08-08
  • vue項目中Toast字體過小,沒有邊距的解決方案

    vue項目中Toast字體過小,沒有邊距的解決方案

    這篇文章主要介紹了vue項目中Toast字體過小,沒有邊距的解決方案。具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-04-04
  • vue.js模仿京東省市區(qū)三級聯(lián)動的選擇組件實例代碼

    vue.js模仿京東省市區(qū)三級聯(lián)動的選擇組件實例代碼

    選擇省市區(qū)是我們大家在填寫地址的時候經(jīng)常會遇到的一個功能,下面這篇文章主要給大家介紹了關(guān)于利用vue.js模仿實現(xiàn)京東省市區(qū)三級聯(lián)動選擇組件的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考借鑒,下面來一起看看吧。
    2017-11-11
  • vuejs 切換導(dǎo)航條高亮(路由菜單高亮)的方法示例

    vuejs 切換導(dǎo)航條高亮(路由菜單高亮)的方法示例

    這篇文章主要介紹了vuejs 切換導(dǎo)航條高亮路由高亮的方法示例,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-05-05

最新評論

西乌珠穆沁旗| 太白县| 宽甸| 灵川县| 达拉特旗| 伽师县| 道孚县| 临澧县| 康乐县| 承德县| 安化县| 集安市| 徐闻县| 湄潭县| 南召县| 长白| 天峻县| 湘潭市| 葫芦岛市| 灵川县| 水富县| 兴安县| 柳江县| 望城县| 象山县| 绥宁县| 汽车| 泽普县| 息烽县| 威远县| 兰西县| 黄冈市| 兴义市| 嘉峪关市| 卓资县| 许昌县| 五华县| 青铜峡市| 咸阳市| 呼玛县| 甘泉县|