vue?iview封裝模態(tài)框的方法
本文實(shí)例為大家分享了vue iview封裝模態(tài)框的具體代碼,供大家參考,具體內(nèi)容如下

子組件
<template>
? <Modal
? ? :value="isShowModal"
? ? :width="width"
? ? :title="title"
? ? @on-visible-change="getFaultModalStatusChange"
? >
? ? <slot name="content"></slot>
? ? <div slot="footer">
? ? ? <div>
? ? ? ? <Button type="success" :loading="loading" @click="submit">確認(rèn)</Button>
? ? ? ? <Button class="cancelButton" @click="cancel">取消</Button>
? ? ? </div>
? ? </div>
? </Modal>
</template>
?
<script>
export default {
? name: "ModalBlock",
? props: {
? ? isShowModal: {
? ? ? type: Boolean,
? ? ? default: false
? ? },
? ? title: {
? ? ? type: String
? ? },
? ? width: {
? ? ? type: Number
? ? },
? ? loading: {
? ? ? type: Boolean,
? ? ? default: false
? ? }
? },
? methods: {
? ? cancel: function() {
? ? ? this.$emit("modalCancel");
? ? },
? ? submit() {
? ? ? this.$emit("modalSubmit");
? ? },
? ? getFaultModalStatusChange(e) {
? ? ? this.$emit("modalStatusChange", e);
? ? }
? }
};
</script>
?
<style scoped>
</style>父組件引入
<template>
? <div>
? ? <Button type="primary" @click="isShowModal = true">Display dialog box</Button>
? ? <modal-block
? ? ? :isShowModal="isShowModal"
? ? ? title="搜索框"
? ? ? :width="640"
? ? ? @modalSubmit="modalSubmit"
? ? ? @modalCancel="modalCancel"
? ? ? @modalStatusChange="modalStatusChange"
? ? >
? ? ? <div slot="content">
? ? ? ? <Row>
? ? ? ? ? <Col span="12">
? ? ? ? ? ? <div>
? ? ? ? ? ? ? <Input
? ? ? ? ? ? ? ? v-model="SearchVal"
? ? ? ? ? ? ? ? icon="ios-search"
? ? ? ? ? ? ? ? placeholder="Enter something..."
? ? ? ? ? ? ? ? style="width: 200px"
? ? ? ? ? ? ? ? @on-click="handleSearch"
? ? ? ? ? ? ? ? autocomplete
? ? ? ? ? ? ? />
? ? ? ? ? ? </div>
? ? ? ? ? ? <div style="height:300px;overflow-y: scroll; margin-top:15px;">
? ? ? ? ? ? ? <RadioGroup v-model="listVal" vertical @on-change="changeSerachVal">
? ? ? ? ? ? ? ? <Radio :label="item.label" v-for="(item,i) in searchList" :key="i">
? ? ? ? ? ? ? ? ? <span>{{item.value}}</span>
? ? ? ? ? ? ? ? ? <Icon :type="item.icon" />
? ? ? ? ? ? ? ? </Radio>
? ? ? ? ? ? ? </RadioGroup>
? ? ? ? ? ? </div>
? ? ? ? ? </Col>
? ? ? ? ? <Col span="12">{{searDtail}}</Col>
? ? ? ? </Row>
? ? ? </div>
? ? </modal-block>
? </div>
</template>
<script>
import ModalBlock from "@/common/ModalItem/ModalSerach";
?
export default {
? name: "ImageUpload",
? components: { ModalBlock },
?
? data() {
? ? return {
? ? ? width: 640,
? ? ? SearchVal: "",
? ? ? listVal: "",
? ? ? searDtail: "",
? ? ? isShowModal: false,
?
? ? ? searchList: [
? ? ? ? {
? ? ? ? ? label: "1",
? ? ? ? ? icon: "logo-apple",
? ? ? ? ? value: "111111"
? ? ? ? },
? ? ? ? {
? ? ? ? ? label: "2",
? ? ? ? ? icon: "logo-apple",
? ? ? ? ? value: "111111"
? ? ? ? },
? ? ? ? {
? ? ? ? ? label: "3",
? ? ? ? ? icon: "logo-apple",
? ? ? ? ? value: "111111"
? ? ? ? },
? ? ? ? {
? ? ? ? ? label: "3",
? ? ? ? ? icon: "logo-apple",
? ? ? ? ? value: "111111"
? ? ? ? },
? ? ? ? {
? ? ? ? ? label: "4",
?
? ? ? ? ? icon: "logo-apple",
? ? ? ? ? value: "111111"
? ? ? ? },
? ? ? ? {
? ? ? ? ? label: "5",
?
? ? ? ? ? icon: "logo-apple",
? ? ? ? ? value: "111111"
? ? ? ? }
? ? ? ]
? ? };
? },
? methods: {
? ? // 模態(tài)輸入框搜索
? ? handleSearch() {
? ? ? console.log(`modalSubmit11111111`);
? ? },
? ? // 點(diǎn)擊模態(tài)框單選框觸發(fā)事件
? ? changeSerachVal(e) {
? ? ? if (e == 1) {
? ? ? ? this.searDtail = "1111";
? ? ? } else if (e == 2) {
? ? ? ? this.searDtail = "22222222222";
? ? ? }
? ? },
? ? // 模態(tài)框確定事件
? ? modalSubmit() {
? ? ? this.isShowModal = false;
? ? },
? ? // 模態(tài)框取消事件
?
? ? modalCancel() {
? ? ? this.isShowModal = false;
? ? },
? ? // 模態(tài)框關(guān)閉觸發(fā)事件
? ? modalStatusChange(e) {
? ? ? if (e === false) {
? ? ? ? this.isShowModal = false;
? ? ? }
? ? }
? }
};
</script>
<style scoped>
</style>一定要加 @on-visible-change="getFaultModalStatusChange" 這個事件,不然點(diǎn)擊按鈕的時候會報錯
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Vue2.0實(shí)現(xiàn)調(diào)用攝像頭進(jìn)行拍照功能 exif.js實(shí)現(xiàn)圖片上傳功能
這篇文章主要為大家詳細(xì)介紹了Vue2.0實(shí)現(xiàn)調(diào)用攝像頭進(jìn)行拍照功能,以及圖片上傳功能引用exif.js,具有一定的參考價值,感興趣的小伙伴們可以參考一下2018-04-04
element el-input directive數(shù)字進(jìn)行控制
本文介紹了vue使用directive 進(jìn)行控制的方法,使用element開發(fā)的過程中遇到循環(huán)的數(shù)據(jù)只能輸入數(shù)字,并且有不要小數(shù)點(diǎn),有需要小數(shù)點(diǎn)的,就有一定的參考價值,有興趣的可以了解一下2018-10-10
vue項目使用高德地圖的定位及關(guān)鍵字搜索功能的實(shí)例代碼(踩坑經(jīng)驗(yàn))
這篇文章主要介紹了vue項目使用高德地圖的定位及關(guān)鍵字搜索功能的實(shí)例代碼,也是小編踩了無數(shù)坑總結(jié)出來的經(jīng)驗(yàn),非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下2020-03-03
Vue?+?Element?實(shí)現(xiàn)按鈕指定間隔時間點(diǎn)擊思路詳解
這篇文章主要介紹了Vue?+?Element?實(shí)現(xiàn)按鈕指定間隔時間點(diǎn)擊,實(shí)現(xiàn)思路大概是通過加一個本地緩存的時間戳,通過時間戳計算指定時間內(nèi)不能點(diǎn)擊按鈕,具體實(shí)現(xiàn)代碼跟隨小編一起看看吧2023-12-12
Vue3+TypeScript實(shí)現(xiàn)遞歸菜單組件的完整實(shí)例
Vue.js中的遞歸組件是一個可以調(diào)用自己的組件,遞歸組件一般用于博客上顯示評論,形菜單或者嵌套菜單,文章主要給大家介紹了關(guān)于Vue3+TypeScript實(shí)現(xiàn)遞歸菜單組件的相關(guān)資料,需要的朋友可以參考下2021-08-08

