VUE+Element中eldialog弹框控制最小宽度
element
A Vue.js 2.0 UI Toolkit for Web
项目地址:https://gitcode.com/gh_mirrors/eleme/element
免费下载资源
·
<template>
<div>
<div>
<el-button @click="dialogFormVisible=true">
打开
</el-button>
</div>
<el-dialog title="弹框" :visible.sync="dialogFormVisible" :width="dialogWidth">
<el-form :model="addline" >
<el-row :gutter="10">
<el-col>
<el-form-item label="标题" prop="title">
<el-input
v-model="addline.title"
placeholder="请输入标题"
/>
</el-form-item>
</el-col>
</el-row>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button @click="dialogFormVisible=false">
取消
</el-button>
</div>
</el-dialog>
</div>
</template>
<script>
export default {
name: 'DialogWidth',
data() {
return {
addline: {
title: ''
},
dialogWidth: 0,
//控制弹框显示
dialogFormVisible: false
}
},
created() {
//初始化调用
this.setDialogWidth()
},
mounted() {
//监听窗口宽度
window.onresize = () => {
return (() => {
this.setDialogWidth()
})()
}
},
methods: {
setDialogWidth() {
console.log(document.body.clientWidth)
var val = document.body.clientWidth
const def = 800 //宽度最小为800,可修改
//窗口宽度小于默认宽度时,将弹框看度设置为50%,可修改
if (val < def) {
this.dialogWidth = '50%'
} else {
//窗口宽度大于默认宽度1200时,将弹框设置为400宽度,可修改
this.dialogWidth = '400px'
}
}
}
}
</script>
GitHub 加速计划 / eleme / element
54.06 K
14.63 K
下载
A Vue.js 2.0 UI Toolkit for Web
最近提交(Master分支:3 个月前 )
c345bb45
7 个月前
a07f3a59
* Update transition.md
* Update table.md
* Update transition.md
* Update table.md
* Update transition.md
* Update table.md
* Update table.md
* Update transition.md
* Update popover.md 7 个月前
更多推荐
已为社区贡献1条内容
所有评论(0)