基于el-dialog封装全局弹窗
dialog
<template>
<div>
<el-dialog title="切换考试" top="9vh" :modal="false" width="600px" :visible.sync="dialogVisible" @close="close" :append-to-body="true">
<el-row>
<el-table :data="examList" border style="width: 100%" height="500">
<el-table-column prop="id" label="编码" width="100"> </el-table-column>
<el-table-column prop="name" label="考试名称" width="300" show-overflow-tooltip> </el-table-column>
<el-table-column prop="examDate" label="考试年月"> </el-table-column>
<el-table-column fixed="right" label="操作" min-width="60">
<template slot-scope="scope">
<el-button @click="handleSelectExam(scope.row)" type="text" size="small">切换</el-button>
</template>
</el-table-column>
</el-table>
</el-row>
</el-dialog>
</div>
</template>
<script>
import { mapActions } from 'vuex'
import * as api from './api'
import store from '@/store'
export default {
name: 'qz-exam-list',
props: {
close: {
type: Function,
default: () => {}
}
},
data () {
return {
examList: [],
dialogVisible: false
}
},
mounted () {},
methods: {
...mapActions('d2admin/theme', ['set']),
open () {
this.dialogVisible = true
this.$nextTick(async () => {
this.examList = await api.getExamList()
// 找到当前的选中
})
},
async handleSelectExam (data) {
await store.dispatch('d2admin/user/setExam', data, { root: true })
// 切换考试后清空导航栏
await store.dispatch('d2admin/page/closeAll')
this.dialogVisible = false
this.close()
}
}
}
</script>
js
import Vue from 'vue'
import selectExamDialog from './dialog' // 引入弹窗组件
const SelectExamDialog = Vue.extend(selectExamDialog)
selectExamDialog.open = function (callback) {
const instance = new SelectExamDialog().$mount()
document.body.appendChild(instance.$el)
instance.close = () => {
callback && callback()
document.body.removeChild(instance.$el)
instance.$destroy()
}
Vue.nextTick(() => {
instance.open()
})
}
// 导出
export default selectExamDialog
全局挂载
import selectExam from '@/components/qz-select-exam'
export default {
async install (Vue, options) {
// 全局可使用
Vue.prototype.$selectExam = selectExam
}
}
作者:whh666
出处:https://www.cnblogs.com/whh666/p/16730877.html
版权:本作品采用「署名-非商业性使用-相同方式共享 4.0 国际」许可协议进行许可。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构