欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Vue彈窗組件的實現(xiàn)方法

 更新時間:2022年09月20日 15:26:05   作者:zlq_csdn  
這篇文章主要為大家詳細介紹了Vue彈窗組件的實現(xiàn)方法,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了Vue彈窗組件的實現(xiàn)具體代碼,供大家參考,具體內(nèi)容如下

彈窗組件包含內(nèi)容:

  • 彈窗遮罩層
  • 內(nèi)容層的實現(xiàn)(涉及slot、props、$on、$emit

實現(xiàn)步驟:

1、搭建組件UI樣式,HTML、css實現(xiàn)遮罩層、內(nèi)容區(qū)
2、編寫彈窗內(nèi)容:通過組件slot插槽接收父組件傳遞過來的彈窗內(nèi)容
3、組件開關(guān)的實現(xiàn):通過父組件傳遞進來的props控制組件的顯示與隱藏,子組件關(guān)閉時通過事件 $emit 觸發(fā)父組件改變狀態(tài)值。

組件代碼實現(xiàn)

<template>
?? ?<div class="modal-bg" v-show="show">
?? ??? ?<div class="modal-container">
?? ??? ??? ?<div class="modal-header">
?? ??? ??? ??? ?{{title}}
?? ??? ??? ?</div>
?? ??? ??? ?<div class="modal-main">
?? ??? ??? ??? ?<!--?
?? ??? ??? ??? ??? ?如果有多個插槽時,可以采用具名插槽的方式實現(xiàn)
?? ??? ??? ??? ??? ?<slot name="main"></slot>
?? ??? ??? ??? ? -->
?? ??? ??? ??? ?<slot></slot>
?? ??? ??? ?</div>
?? ??? ??? ?<div class="modal-footer">
?? ??? ??? ??? ?<button @click="close">關(guān) 閉</button>
?? ??? ??? ??? ?<button @click="submit">確 定</button>
?? ??? ??? ?</div>
?? ??? ?</div>
?? ?</div>
</template>
<script>
export default{
?? ?name: 'modal',
?? ?data() {
?? ??? ?return {}?? ?
?? ?},
?? ?props: {
?? ??? ?show: { ? ?// 控制彈窗展示
?? ??? ??? ?type: Boolean,
?? ??? ??? ?default: false,?? ?
?? ??? ??? ?required: true, ? // 必傳遞
?? ??? ?},
?? ??? ?title: {
?? ??? ??? ?type: String,
?? ??? ??? ?default: 'title',
?? ??? ?}
?? ?},
?? ?methods: {
?? ??? ?// 通過事件綁定及$emit來執(zhí)行父組件的方法,改變彈窗展示狀態(tài)
?? ??? ?close() {
?? ??? ??? ?this.$emit("hideModal");?? ?
?? ??? ?},
?? ??? ?submit() {
?? ??? ??? ?this.$emit("submit");?? ?
?? ??? ?}
?? ?}
}
</script>
<style>
.modal-bg{
?? ?position: fixed;
?? ?top: 0;
?? ?right: 0;
?? ?bottom: 0;
?? ?left: 0;
?? ?display: flex;
?? ?justify-content: center;
?? ?align-items: center;
?? ?background: rgba(0, 0, 0, .4);
?? ?z-index:999;
}
.modal-container{
?? ?border-radius: 8px;
?? ?background: #fff;
}
.model-header{
?? ?heigth: 60px;
?? ?background: blue;
?? ?color:#fff;
}
.modal-main {
?? ?padding: 20px 40px;
}
.modal-footer{
?? ?height: 60px;
?? ?display: flex;
?? ?justify-content: center;
?? ?align-item: center;
?? ?border-top: 1px solid #000;
}
.modal-footer button{
?? ?width:100px;
}
</style>

父組件中調(diào)用:

<template>
?? ?<div>
?? ??? ?<Modal :show="show" :title="title" @hideModal="hideModal" @submit="submit">
?? ??? ??? ?<!--?
?? ??? ??? ??? ?向 slot 插槽中展示的內(nèi)容?
?? ??? ??? ??? ?具名傳遞: <div slot="main">我是具名插槽傳遞內(nèi)容的</div>
?? ??? ??? ?-->
?? ??? ??? ?<div>我是slot中的內(nèi)容</div>
?? ??? ?</Modal>
?? ?</div>
</template>
<script>
import Modal from "./modal.vue";
export default {
?? ?name: "parentVue",
?? ?data() {
?? ??? ?return {
?? ??? ??? ?show: false,
?? ??? ??? ?title: "我是彈窗標(biāo)題",
?? ??? ?}?? ?
?? ?},
?? ?components: {
?? ??? ?Modal,
?? ?},
?? ?methods: {
?? ??? ?// 關(guān)閉彈窗
?? ??? ?hideModal() {
?? ??? ??? ?this.show = false;
?? ??? ?}
?? ??? ?// 顯示彈窗
?? ??? ?submit() {
?? ??? ??? ?this.show = true;?? ?
?? ??? ?}
?? ?}
}
</script>
<style>

</style>

溫馨提示:

目前的市面上,有很多現(xiàn)有的 UI 組件庫,如Element-UI等,很少會直接編寫UI樣式代碼之類的操作,可以直接使用第三方庫完成項目需求。

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

相關(guān)文章

  • 在vue 中使用 less的教程詳解

    在vue 中使用 less的教程詳解

    這篇文章主要介紹了在vue 中使用 less 的相關(guān)知識,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下
    2018-09-09
  • 用vue的雙向綁定簡單實現(xiàn)一個todo-list的示例代碼

    用vue的雙向綁定簡單實現(xiàn)一個todo-list的示例代碼

    本篇文章主要介紹了用vue的雙向綁定簡單實現(xiàn)一個todo的示例代碼,具有一定的參考價值,有興趣的可以了解一下
    2017-08-08
  • vue2+elementui進行hover提示的使用

    vue2+elementui進行hover提示的使用

    本文主要介紹了vue2+elementui進行hover提示的使用,主要分為外部和內(nèi)部,具有一定的參考價值,感興趣的可以了解一下
    2021-11-11
  • 詳解vue3?響應(yīng)式的實現(xiàn)原理

    詳解vue3?響應(yīng)式的實現(xiàn)原理

    Vue.js?3.0?為了解決?Object.defineProperty?的這些缺陷,使用?Proxy?API?重寫了響應(yīng)式部分,并獨立維護和發(fā)布整個?reactivity?庫,這篇文章主要介紹了vue3?響應(yīng)式的實現(xiàn)原理,需要的朋友可以參考下
    2022-06-06
  • VueX學(xué)習(xí)之modules和namespacedVueX詳細教程

    VueX學(xué)習(xí)之modules和namespacedVueX詳細教程

    這篇文章主要為大家介紹了VueX學(xué)習(xí)之modules和namespacedVueX詳細教程,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-06-06
  • vue3內(nèi)嵌iframe的傳參與接收參數(shù)代碼示例

    vue3內(nèi)嵌iframe的傳參與接收參數(shù)代碼示例

    這篇文章主要給大家介紹了關(guān)于vue3內(nèi)嵌iframe的傳參與接收參數(shù)的相關(guān)資料,Vue項目中使用iframe及傳值功能相信有不少人都遇到過,需要的朋友可以參考下
    2023-07-07
  • vue自定義加載指令v-loading占位圖指令v-showimg

    vue自定義加載指令v-loading占位圖指令v-showimg

    這篇文章主要為大家介紹了vue自定義加載指令和v-loading占位圖指令v-showimg的示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-08-08
  • vue插件tab選項卡使用小結(jié)

    vue插件tab選項卡使用小結(jié)

    這篇文章主要為大家詳細介紹了vue插件tab選項卡的使用方法,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-10-10
  • elementui?Select選擇器嵌套tree實現(xiàn)TreeSelect方式

    elementui?Select選擇器嵌套tree實現(xiàn)TreeSelect方式

    這篇文章主要介紹了elementui?Select選擇器嵌套tree實現(xiàn)TreeSelect方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2023-10-10
  • Vue組件封裝上傳圖片和視頻的示例代碼

    Vue組件封裝上傳圖片和視頻的示例代碼

    這篇文章主要介紹了Vue封裝上傳圖片和視頻的組件,本文通過實例代碼給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2021-07-07

最新評論