国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

記錄--vue3優(yōu)雅的使用element-plus的dialog

這篇具有很好參考價值的文章主要介紹了記錄--vue3優(yōu)雅的使用element-plus的dialog。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

這里給大家分享我在網(wǎng)上總結(jié)出來的一些知識,希望對大家有所幫助

記錄--vue3優(yōu)雅的使用element-plus的dialog

如何優(yōu)雅的基于 element-plus,封裝一個夢中情 dialog

優(yōu)點

擺脫繁瑣的 visible 的命名,以及反復的重復 dom。

想法

將 dialog 封裝成一個函數(shù)就能喚起的組件。如下:

addDialog({
  title: "測試", //彈窗名
  component: TestVue, //組件
  width: "400px", //彈窗大小
  props: {
    //傳給組件的參數(shù)
    id: 0
  },
  callBack: (data: any) => {
    //當彈窗任務結(jié)束后,調(diào)用父頁面的回掉函數(shù)。(比如我新增完成了需要刷新列表頁面)
    console.log("回調(diào)函數(shù)", data)
  }
})

效果圖

?

記錄--vue3優(yōu)雅的使用element-plus的dialog

基于 el-dialog 進行初步封裝

// index.ts
import { reactive } from "vue"
type dialogOptions = {
  title: string
  component: any
  props?: Object
  width: string
  visible?: any
  callBack?: Function
}
export const dialogList: dialogOptions[] = reactive([])

export const addDialog = (options: dialogOptions) => {
  dialogList.push(Object.assign(options, { visible: true }))
}

export const closeDialog = (item: dialogOptions, i: number, args?: any, isNativeClose?: boolean) => {
  dialogList.splice(i, 1)
  if (!isNativeClose) item.callBack && item.callBack(...args)
}
<template>
  <Teleport to="body">
    <el-dialog
      v-for="(item, index) in dialogList"
      :key="index"
      :title="item.title"
      :width="item.width"
      v-model="item.visible"
      @close="() => closeDialog(item, index, '', true)"
    >
      <component :is="item.component" v-bind="item.props" @close="(...args:any) => closeDialog(item, index, args)" />
    </el-dialog>
  </Teleport>
</template>

<script setup lang="ts">
  import { dialogList, closeDialog } from "./index"
</script>
  • 首先定義了 dialogList,它包含了所有彈窗的信息。
  • component 使用 componet is 去動態(tài)加載子組件
  • addDialog 調(diào)用喚起彈窗的函數(shù)
  • closeDialog 關閉彈窗的函數(shù)

在app.vue中掛載

<script setup>
import Mydialog from "@/components/gDialog/index.vue"
</script>

<template>
 <router-view />
 <Mydialog></Mydialog>
</template>

<style scoped>

</style>

使用

創(chuàng)建一個彈窗組件

<!-- test.vue -->
<template>
  父彈窗
  <el-button type="primary" @click="openChildDialog">打開子dialog</el-button>
  <el-button type="primary" @click="closeDialog">關閉彈窗</el-button>
</template>

<script setup lang="ts">
  import { addDialog } from "@/components/gDialog/index"
  import childVue from "./child.vue"
  const props = defineProps(["id"])
  console.log(props.id, "props")
  const emit = defineEmits(["close"])
  const closeDialog = () => {
    emit("close", 1, 2, 34)
  }
  const openChildDialog = () => {
    addDialog({
      title: "我是子dialog",
      width: "500px",
      component: childVue
    })
  }
</script>

在列表頁面喚醒彈窗

<!-- list.vue -->
<template>
  列表頁
  <el-button type="primary" @click="openDialog">打開dialog</el-button>
</template>
<script setup lang="ts">
import { addDialog } from "@/components/gDialog/index"
import TestDialog from "./test.vue"
const openDialog = () => {
  addDialog({
    title: "我是dialog",
    width: "500px",
    props:{
      id:0
    }
    component: TestDialog,
    callBack: (data: any) => {
      //當彈窗任務結(jié)束后,調(diào)用父頁面的回掉函數(shù)。(比如我新增完成了需要刷新列表頁面)
      console.log("回調(diào)函數(shù)", data)
    }
  })
}

多層級彈窗嵌套

<!-- child.vue -->
<template>
  子彈窗
  <el-button type="primary" @click="closeDialog">關閉彈窗</el-button>
</template>

<script setup lang="ts">
  import { addDialog } from "@/components/gDialog/index"
  const emit = defineEmits(["close"])
  const closeDialog = () => {
    emit("close", 1, 2, 34)
  }
</script>

附上代碼

代碼

本文轉(zhuǎn)載于:

https://juejin.cn/post/7224007334514638903

如果對您有所幫助,歡迎您點個關注,我會定時更新技術文檔,大家一起討論學習,一起進步。

?記錄--vue3優(yōu)雅的使用element-plus的dialog文章來源地址http://www.zghlxwxcb.cn/news/detail-448052.html

到了這里,關于記錄--vue3優(yōu)雅的使用element-plus的dialog的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領支付寶紅包贊助服務器費用

相關文章

  • 使用 Vite + Vue3 + Element-Plus + Pinia + Ts 搭建 Vue3 項目

    使用 Vite + Vue3 + Element-Plus + Pinia + Ts 搭建 Vue3 項目

    Vite 需要 Node.js 版本 14.18+,16+。然而,有些模板需要依賴更高的 Node 版本才能正常運行,當你的包管理器發(fā)出警告時,請注意升級你的 Node 版本。 首先 npm 輸入: Project name :項目名稱 Select a framework :選擇一個框架 Select a variant :選擇 ts 或者 js 輸入項目名稱后選擇 vue 選擇

    2024年02月09日
    瀏覽(26)
  • Vue3使用element-plus實現(xiàn)彈窗效果-demo
  • Vue3中動態(tài)綁定:disabled element-plus使用方法

    @change=\\\"whetherFlag($event)\\\"? 根據(jù)value值判斷是否禁用?:disabled=\\\"isShow\\\" 初始值為禁用狀態(tài) const isShow = refboolean(true); ?根據(jù)value的值判斷是否禁用 ?

    2024年01月25日
    瀏覽(29)
  • vue3.x結(jié)合element-plus如何使用icon圖標

    vue3.x結(jié)合element-plus如何使用icon圖標

    ?基于 Vue 3的Element Plus如何使用icon圖標 首先注意Element Plus版本:官網(wǎng)如圖所示, ?基于vue3的具體如何使用: 參考官網(wǎng)文檔: 1.首先選擇一種方式安裝 ?2.然后全局注冊圖標 在main.js或main.ts文件中引入: ?3.然后就可以使用了,具體實例如下: 使用方式1:輸入框中使用 輸入框

    2023年04月08日
    瀏覽(21)
  • 解決Vue3 使用Element-Plus導航刷新active高亮消失

    解決Vue3 使用Element-Plus導航刷新active高亮消失

    啟用路由模式會在激活導航時以 index 作為 path 進行路由跳轉(zhuǎn) 使用 default-active 來設置加載時的激活項。 接下來打印一下選中項index和index路徑, 刷新也是沒有任何問題的,active不會消失,整體代碼如下:

    2024年02月14日
    瀏覽(20)
  • 【Vue3 博物館管理系統(tǒng)】使用Vue3、Element-plus菜單組件構(gòu)建前臺用戶菜單

    【Vue3 博物館管理系統(tǒng)】使用Vue3、Element-plus菜單組件構(gòu)建前臺用戶菜單

    第一章 定制上中下(頂部菜單、底部區(qū)域、中間主區(qū)域顯示)三層結(jié)構(gòu)首頁 第二章 使用Vue3、Element-plus菜單組件構(gòu)建菜單 [第三章 使用Vue3、Element-plus菜單組件構(gòu)建輪播圖] [第四章 使用Vue3、Element-plus菜單組件構(gòu)建組圖文章] 上一章節(jié)給我們把博物館管理系統(tǒng)打了個地基,基本

    2024年02月13日
    瀏覽(36)
  • Vue3+Element Plus 關于Dialog彈出Form表單,使用resetFields重置無效的解決

    主要參考了element-plus官方的表單重置按鈕(官方Form例子任意reset按鈕),然后試了試他的ref綁定,發(fā)現(xiàn)可以完美解決重置問題。 第一步:給Form表單綁定ref。綁定ref?的值為refFormInstance();這里注意表單el-form-item必須有prop屬性。 2.第二步:在你想要重置的地方調(diào)用重置表單方法

    2024年01月21日
    瀏覽(23)
  • [Vue3 博物館管理系統(tǒng)] 使用Vue3、Element-plus tabs組件構(gòu)建選項卡功能

    [Vue3 博物館管理系統(tǒng)] 使用Vue3、Element-plus tabs組件構(gòu)建選項卡功能

    第一章 定制上中下(頂部菜單、底部區(qū)域、中間主區(qū)域顯示)三層結(jié)構(gòu)首頁 第二章 使用Vue3、Element-plus菜單組件構(gòu)建菜單 第三章 使用Vue3、Element-plus走馬燈組件構(gòu)建輪播圖 第四章 使用Vue3、Element-plus tabs組件構(gòu)建選項卡功能 [第五章 使用Vue3、Element-plus菜單組件構(gòu)建組圖文章

    2024年02月09日
    瀏覽(34)
  • vue3使用element-plus 樹組件(el-tree)數(shù)據(jù)回顯

    html搭建結(jié)構(gòu) js 非常好用,拿過來修改一下check事件,ref獲取就直接可以使用了?

    2024年04月09日
    瀏覽(99)
  • 【已解決】Vue3使用Element-plus按需加載時消息彈框ElMessage沒有樣式

    【已解決】Vue3使用Element-plus按需加載時消息彈框ElMessage沒有樣式

    Element-plus在使用ElMessage消息彈框的時候沒有樣式,按照官方的按需加載的方式引入的 1、Element-plus使用了自動按需導入,vite.config.js配置如下: 代碼手動導入了API,如下 解決沒有樣式的問題 將上述代碼導入import部分的代碼去掉,直接調(diào)用。 使用的時候直接調(diào)用 成功解決!

    2024年02月10日
    瀏覽(263)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領取紅包,優(yōu)惠每天領

二維碼1

領取紅包

二維碼2

領紅包