国产chinesehdxxxx野外,国产av无码专区亚洲av琪琪,播放男人添女人下边视频,成人国产精品一区二区免费看,chinese丰满人妻videos

ElementPlus Dialog 對話框

2021-09-26 17:49 更新

Dialog 對話框

在保留當前頁面狀態(tài)的情況下,告知用戶并承載相關(guān)操作。

基本用法

Dialog 彈出一個對話框,適合需要定制性更大的場景。


需要設(shè)置 model-value / v-model 屬性,它接收 Boolean,當為 true 時顯示 Dialog。Dialog 分為兩個部分:body 和 footer,footer 需要具名為 footer 的 slot。title 屬性用于定義標題,它是可選的,默認值為空。最后,本例還展示了 before-close 的用法。

<template>
  <el-button type="text" @click="dialogVisible = true">點擊打開 Dialog</el-button>

<el-dialog
  title="提示"
  v-model="dialogVisible"
  width="30%"
  :before-close="handleClose"
>
  <span>這是一段信息</span>
  <template #footer>
    <span class="dialog-footer">
      <el-button @click="dialogVisible = false">取 消</el-button>
      <el-button type="primary" @click="dialogVisible = false">確 定</el-button>
    </span>
  </template>
</el-dialog>
</template>

<script>
  export default {
    data() {
      return {
        dialogVisible: false,
      }
    },
    methods: {
      handleClose(done) {
        this.$confirm('確認關(guān)閉?')
          .then((_) => {
            done()
          })
          .catch((_) => {})
      },
    },
  }
</script>

before-close 僅當用戶通過點擊關(guān)閉圖標或遮罩關(guān)閉 Dialog 時起效。如果你在 footer 具名 slot 里添加了用于關(guān)閉 Dialog 的按鈕,那么可以在按鈕的點擊回調(diào)函數(shù)里加入 before-close 的相關(guān)邏輯。

自定義內(nèi)容

Dialog 組件的內(nèi)容可以是任意的,甚至可以是表格或表單,下面是應(yīng)用了 Element Plus Table 和 Form 組件的兩個樣例。


<template>
  <el-button type="text" @click="dialogTableVisible = true"
  >打開嵌套表格的 Dialog</el-button
>

<el-dialog title="收貨地址" v-model="dialogTableVisible">
  <el-table :data="gridData">
    <el-table-column property="date" label="日期" width="150"></el-table-column>
    <el-table-column property="name" label="姓名" width="200"></el-table-column>
    <el-table-column property="address" label="地址"></el-table-column>
  </el-table>
</el-dialog>

<!-- Form -->
<el-button type="text" @click="dialogFormVisible = true"
  >打開嵌套表單的 Dialog</el-button
>

<el-dialog title="收貨地址" v-model="dialogFormVisible">
  <el-form :model="form">
    <el-form-item label="活動名稱" :label-width="formLabelWidth">
      <el-input v-model="form.name" autocomplete="off"></el-input>
    </el-form-item>
    <el-form-item label="活動區(qū)域" :label-width="formLabelWidth">
      <el-select v-model="form.region" placeholder="請選擇活動區(qū)域">
        <el-option label="區(qū)域一" value="shanghai"></el-option>
        <el-option label="區(qū)域二" value="beijing"></el-option>
      </el-select>
    </el-form-item>
  </el-form>
  <template #footer>
    <span class="dialog-footer">
      <el-button @click="dialogFormVisible = false">取 消</el-button>
      <el-button type="primary" @click="dialogFormVisible = false"
        >確 定</el-button
      >
    </span>
  </template>
</el-dialog>
</template>

<script>
  export default {
    data() {
      return {
        gridData: [
          {
            date: '2016-05-02',
            name: '王小虎',
            address: '上海市普陀區(qū)金沙江路 1518 弄',
          },
          {
            date: '2016-05-04',
            name: '王小虎',
            address: '上海市普陀區(qū)金沙江路 1518 弄',
          },
          {
            date: '2016-05-01',
            name: '王小虎',
            address: '上海市普陀區(qū)金沙江路 1518 弄',
          },
          {
            date: '2016-05-03',
            name: '王小虎',
            address: '上海市普陀區(qū)金沙江路 1518 弄',
          },
        ],
        dialogTableVisible: false,
        dialogFormVisible: false,
        form: {
          name: '',
          region: '',
          date1: '',
          date2: '',
          delivery: false,
          type: [],
          resource: '',
          desc: '',
        },
        formLabelWidth: '120px',
      }
    },
  }
</script>

嵌套的 Dialog

如果需要在一個 Dialog 內(nèi)部嵌套另一個 Dialog,需要使用 append-to-body 屬性。


正常情況下,我們不建議使用嵌套的 Dialog,如果需要在頁面上同時顯示多個 Dialog,可以將它們平級放置。對于確實需要嵌套 Dialog 的場景,我們提供了append-to-body屬性。將內(nèi)層 Dialog 的該屬性設(shè)置為 true,它就會插入至 body 元素上,從而保證內(nèi)外層 Dialog 和遮罩層級關(guān)系的正確。

<template>
  <el-button type="text" @click="outerVisible = true"
    >點擊打開外層 Dialog</el-button
  >

  <el-dialog title="外層 Dialog" v-model="outerVisible">
    <el-dialog
      width="30%"
      title="內(nèi)層 Dialog"
      v-model="innerVisible"
      append-to-body
    >
    </el-dialog>
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="outerVisible = false">取 消</el-button>
        <el-button type="primary" @click="innerVisible = true"
          >打開內(nèi)層 Dialog</el-button
        >
      </div>
    </template>
  </el-dialog>
</template>

<script>
  export default {
    data() {
      return {
        outerVisible: false,
        innerVisible: false,
      }
    },
  }
</script>

居中布局

標題和底部可水平居中


將center設(shè)置為true即可使標題和底部居中。center僅影響標題和底部區(qū)域。Dialog 的內(nèi)容是任意的,在一些情況下,內(nèi)容并不適合居中布局。如果需要內(nèi)容也水平居中,請自行為其添加 CSS。

<template>
  <el-button type="text" @click="centerDialogVisible = true"
  >點擊打開 Dialog</el-button
>

<el-dialog title="提示" v-model="centerDialogVisible" width="30%" center>
  <span>需要注意的是內(nèi)容是默認不居中的</span>
  <template #footer>
    <span class="dialog-footer">
      <el-button @click="centerDialogVisible = false">取 消</el-button>
      <el-button type="primary" @click="centerDialogVisible = false"
        >確 定</el-button
      >
    </span>
  </template>
</el-dialog>
</template>

<script>
  export default {
    data() {
      return {
        centerDialogVisible: false,
      }
    },
  }
</script>

Dialog 的內(nèi)容是懶渲染的,即在第一次被打開之前,傳入的默認 slot 不會被渲染到 DOM 上。因此,如果需要執(zhí)行 DOM 操作,或通過 ref 獲取相應(yīng)組件,請在 open 事件回調(diào)中進行。

關(guān)閉時銷毀 DOM 內(nèi)容

可在 Dialog 沒有顯示時,銷毀 Dialog 里的內(nèi)容以達到減少 DOM 節(jié)點的作用


需要注意的是,當這個屬性被啟用時,Dialog 內(nèi)并不會有任何的 DOM 節(jié)點存在,除了 overlay header(如果有) footer(如果有)

<template>
  <el-button type="text" @click="centerDialogVisible = true"
  >點擊打開 Dialog</el-button
>

<el-dialog
  title="提示"
  v-model="centerDialogVisible"
  width="30%"
  destroy-on-close
  center
>
  <span>需要注意在 Dialog 打開前是這條內(nèi)容和下面的內(nèi)容都是不會被渲染的</span>
  <strong>額外的內(nèi)容</strong>
  <template #footer>
    <span class="dialog-footer">
      <el-button @click="centerDialogVisible = false">取 消</el-button>
      <el-button type="primary" @click="centerDialogVisible = false"
        >確 定</el-button
      >
    </span>
  </template>
</el-dialog>
</template>

<script>
  export default {
    data() {
      return {
        centerDialogVisible: false,
      }
    },
  }
</script>

當使用 modal = false 時,請一定保證 Dialog 的 append-to-body 屬性為 true, 因為 Dialog 的定位是通過 position: relative 來定位的,當 modal 不存在當時候,如果不將 Dialog 插入到 Document.Body 下,則會根據(jù)當前的位置進行定位,會導(dǎo)致樣式錯亂

Attributes

參數(shù)說明類型可選值默認值
model-value / v-model是否顯示 Dialogboolean
titleDialog 的標題,也可通過具名 slot (見下表)傳入string
widthDialog 的寬度string / number50%
fullscreen是否為全屏 Dialogbooleanfalse
topDialog CSS 中的 margin-top 值string15vh
modal是否需要遮罩層booleantrue
append-to-bodyDialog 自身是否插入至 body 元素上。嵌套的 Dialog 必須指定該屬性并賦值為 truebooleanfalse
lock-scroll是否在 Dialog 出現(xiàn)時將 body 滾動鎖定booleantrue
custom-classDialog 的自定義類名string
open-delayDialog 打開的延時時間,單位毫秒number0
close-delayDialog 關(guān)閉的延時時間,單位毫秒number0
close-on-click-modal是否可以通過點擊 modal 關(guān)閉 Dialogbooleantrue
close-on-press-escape是否可以通過按下 ESC 關(guān)閉 Dialogbooleantrue
show-close是否顯示關(guān)閉按鈕booleantrue
before-close關(guān)閉前的回調(diào),會暫停 Dialog 的關(guān)閉function(done),done 用于關(guān)閉 Dialog
center是否對頭部和底部采用居中布局booleanfalse
destroy-on-close關(guān)閉時銷毀 Dialog 中的元素booleanfalse

Slot

name說明
Dialog 的內(nèi)容
titleDialog 標題區(qū)的內(nèi)容
footerDialog 按鈕操作區(qū)的內(nèi)容

Events

事件名稱說明回調(diào)參數(shù)
openDialog 打開的回調(diào)
openedDialog 打開動畫結(jié)束時的回調(diào)
closeDialog 關(guān)閉的回調(diào)
closedDialog 關(guān)閉動畫結(jié)束時的回調(diào)


以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號