全局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

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐