全局loading

使用v-loading指令方式,因为Dialog的最外层元素是全屏,故遮罩为全屏。

<template>
  <div>
    <el-button type="text" @click="dialogVisible = true; loading = true">Open Dialog</el-button>

    <el-dialog
      title="提示"
      :visible.sync="dialogVisible"
      width="30%"
      v-loading="loading"
    >
      <span>this is a demo</span>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      loading: false,
      dialogVisible: false
    };
  }
};
</script>

局部loading

使用服务方式时,传入dialog DOM 节点,遮罩在dialog处。

<template>
  <div>
    <el-button type="text" @click="open">Open Dialog</el-button>

    <el-dialog title="提示" :visible.sync="dialogVisible" width="30%">
      <span>this is a demo</span>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      dialogVisible: false
    };
  },
  methods: {
    open() {
      this.dialogVisible = true;
      this.$loading({
        target: '.el-dialog'
      });
    }
  }
};
</script>

请添加图片描述

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐