惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

GbyAI
GbyAI
Blog — PlanetScale
Blog — PlanetScale
The GitHub Blog
The GitHub Blog
Microsoft Security Blog
Microsoft Security Blog
I
InfoQ
A
About on SuperTechFans
T
The Blog of Author Tim Ferriss
D
DataBreaches.Net
L
LangChain Blog
F
Fortinet All Blogs
C
Check Point Blog
Google DeepMind News
Google DeepMind News
云风的 BLOG
云风的 BLOG
Engineering at Meta
Engineering at Meta
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
H
Help Net Security
J
Java Code Geeks
月光博客
月光博客
H
Hackread – Cybersecurity News, Data Breaches, AI and More
IT之家
IT之家
aimingoo的专栏
aimingoo的专栏
小众软件
小众软件
宝玉的分享
宝玉的分享
Jina AI
Jina AI

博客园 - aquilahkj

在Flutter中使用极光推送集成华为通道踩坑 Flutter中生成Android的jks签名文件并使用 ABP Vnext使用mysql数据库 使用Vue Baidu Map对百度地图实现输入框搜索定位 在dotnet core实现类似crontab的定时任务 使用Docker搭建HttpRunnerManager环境 docker搭建nginx反代ngrok服务 - aquilahkj 开源一个基于dotnet standard的轻量级的ORM框架-Light.Data VMware Fusion下安装Win8启用Hyper-V centos下安装rinetd(转载) 在Mac OS X上安装JavaHL SVN数据仓库配置 在MONO下实现WCF所遇到的问题 mysql 创建 主键索引 唯一索引 全文索引 多列索引 添加索引 CentOS 6.0 安装 MONO 2.10.8 关于MYSQL 远程登录的授权方法 命令 CentOS 6.0 编译安装 MySQL 5.5.17 linux下允许root用户远程登录 Linux Vi命令
实现ElementUI Dialog宽度响应式变化
aquilahkj · 2019-08-06 · via 博客园 - aquilahkj

  在ElementUI的Dialog中,需要实现其宽度随浏览器宽度变化而变化,并设定默认值,当浏览器宽度大于该值时,Dialog保持该宽度,小于该值时,使用100%宽度。

代码使用 window.onresize 事件触发变化,具体Demo代码如下

<template>
  <div class="app-container">
    <div class="filter-container">
      <el-button type="primary" icon="el-icon-edit" @click="dialogFormVisible=true">
        打开
      </el-button>
    </div>
    <el-dialog title="Test" :visible.sync="dialogFormVisible" :width="dialogWidth">
      <el-form ref="dataForm" :model="temp" label-position="left" label-width="110px">
        <el-row :gutter="10">
          <el-col>
            <el-form-item label="标题" prop="title">
              <el-input
                v-model="temp.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: 'DialogWidthDemo',
  components: {
  },
  data() {
    return {
      temp: {
        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 // 默认宽度
      if (val < def) {
        this.dialogWidth = '100%'
      } else {
        this.dialogWidth = def + 'px'
      }
    }
  }
}
</script>

<style scoped>

</style>

 效果如下