dialog 对话框垂直居中

ps :样式不能写在scoped里面,否则失效

1. 给dialog 起个类名,custom-class="dialogStyle"

<el-dialog
      v-model="dialogVisible"
      :title="dialogTitle"
      width="38%"
      center
      destroy-on-close
      V-el-drag-dialog
      V-if="dialogVisible"
      append-to-body
      custom-class="dialogStyle"
      :before-close="handleClose"
    >
      <!-- formID 指的是ID -->
      <indexForm
        :newFormdata="newFormdata"
        ref="fromViewRef"
      />
    </el-dialog>

2. 直接复制粘贴此代码即可生效。

<style>
.dialogStyle {
  display: flex;
  flex-direction: column;
  margin: 0 !important;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  max-height: calc(100% - 30px);
  max-width: calc(100% - 30px);
}
</style>

如果dialog 内容过多要有滚动,需加下面这句

::v-deep .el-dialog .el-dialog__body{
  flex:1; 
  overflow: auto; 
}

猜你喜欢

转载自blog.csdn.net/CMDN123456/article/details/131590531