彈出層容器,用于展示彈窗、信息提示等內(nèi)容,支持多個(gè)彈出層疊加展示
import Vue from 'vue';
import { Popup } from 'vant';
Vue.use(Popup);
通過(guò)v-model控制彈出層是否展示
<van-cell is-link @click="showPopup">展示彈出層</van-cell>
<van-popup v-model="show">內(nèi)容</van-popup>
export default {
data() {
return {
show: false
}
},
methods: {
showPopup() {
this.show = true;
}
}
};
通過(guò)position屬性設(shè)置彈出位置,默認(rèn)居中彈出,可以設(shè)置為top、bottom、left、right
<van-popup
v-model="show"
position="top"
:style="{ height: '20%' }"
/>
設(shè)置closeable屬性后,會(huì)在彈出層的右上角顯示關(guān)閉圖標(biāo),并且可以通過(guò)close-icon屬性自定義圖標(biāo),使用close-icon-position屬性可以自定義圖標(biāo)位置
<van-popup
v-model="show"
closeable
position="bottom"
:style="{ height: '20%' }"
/>
<!-- 自定義圖標(biāo) -->
<van-popup
v-model="show"
closeable
close-icon="close"
position="bottom"
:style="{ height: '20%' }"
/>
<!-- 圖標(biāo)位置 -->
<van-popup
v-model="show"
closeable
close-icon-position="top-left"
position="bottom"
:style="{ height: '20%' }"
/>
設(shè)置round屬性后,彈窗會(huì)根據(jù)彈出位置添加不同的圓角樣式
<van-popup
v-model="show"
round
position="bottom"
:style="{ height: '20%' }"
/>
彈出層默認(rèn)掛載到組件所在位置,可以通過(guò)get-container屬性指定掛載位置
<!-- 掛載到 body 節(jié)點(diǎn)下 -->
<van-popup v-model="show" get-container="body" />
<!-- 掛載到 #app 節(jié)點(diǎn)下 -->
<van-popup v-model="show" get-container="#app" />
<!-- 通過(guò)函數(shù)指定掛載位置 -->
<van-popup v-model="show" :get-container="getContainer" />
export default {
methods: {
// 返回一個(gè)特定的 DOM 節(jié)點(diǎn),作為掛載的父節(jié)點(diǎn)
getContainer() {
return document.querySelector('.my-container');
}
}
}
注意:使用 get-container 屬性的組件不能為根節(jié)點(diǎn)
參數(shù) | 說(shuō)明 | 類(lèi)型 | 默認(rèn)值 |
---|---|---|---|
v-model | 當(dāng)前組件是否顯示 | boolean | false |
overlay | 是否顯示遮罩層 | boolean | true |
position | 彈出位置,可選值為 top bottom right left | string | center |
overlay-class | 自定義遮罩層類(lèi)名 | string | - |
overlay-style | 自定義遮罩層樣式 | object | - |
duration | 動(dòng)畫(huà)時(shí)長(zhǎng),單位秒 | number | string | 0.3 |
round v2.0.7 | 是否顯示圓角 | boolean | false |
lock-scroll | 是否鎖定背景滾動(dòng) | boolean | true |
lazy-render | 是否在顯示彈層時(shí)才渲染節(jié)點(diǎn) | boolean | true |
close-on-popstate v2.2.10 | 是否在頁(yè)面回退時(shí)自動(dòng)關(guān)閉 | boolean | false |
close-on-click-overlay | 是否在點(diǎn)擊遮罩層后關(guān)閉 | boolean | true |
closeable v2.2.0 | 是否顯示關(guān)閉圖標(biāo) | boolean | false |
close-icon v2.2.0 | 關(guān)閉圖標(biāo)名稱(chēng)或圖片鏈接 | string | cross |
close-icon-position v2.2.2 | 關(guān)閉圖標(biāo)位置,可選值為top-left bottom-left bottom-right | string | top-right |
transition | 動(dòng)畫(huà)類(lèi)名,等價(jià)于 transtion 的name 屬性 | string | - |
get-container | 指定掛載的節(jié)點(diǎn) | string | () => Element | - |
safe-area-inset-bottom v2.2.1 | 是否開(kāi)啟 底部安全區(qū)適配 | boolean | false |
事件名 | 說(shuō)明 | 回調(diào)參數(shù) |
---|---|---|
click | 點(diǎn)擊彈出層時(shí)觸發(fā) | event: Event |
open | 打開(kāi)彈出層時(shí)觸發(fā) | - |
opened | 打開(kāi)彈出層且動(dòng)畫(huà)結(jié)束后觸發(fā) | - |
close | 關(guān)閉彈出層時(shí)觸發(fā) | - |
closed | 關(guān)閉彈出層且動(dòng)畫(huà)結(jié)束后觸發(fā) | - |
click-overlay | 點(diǎn)擊遮罩層時(shí)觸發(fā) | - |
更多建議: