effect
Encapsulate loading (can also be used directly, encapsulated for ease of multiple calls)
Component Definition:
import { Loading } from "element-ui"; export const servicesLoading = (node,str,lock) => { return ({ target: (node),//loads the DOM node that needs to be overridden, defaults to body. text: str,//Loading Copy lock,//Same modifiers as v-loading // backgroundColor: 'rgba(55,55,55,0.4)',//background color // spinner: 'el-icon-loading',//loading icons }) }
Page Usage
<template> <div> <el-button type="text" round @click="dialogVisible=true">show (a ticket)dialog</el-button> <el-dialog title="Tip." :="dialogVisible" :close-on-click-modal="false" :append-to-body="true" width="30%"> <span>Here's a message.</span> <span slot="footer" class="dialog-footer"> <el-button @click="dialogVisible = false">get have to</el-button> <el-button type="primary" @click="sureFunc">real order</el-button> </span> </el-dialog> </div> </template> <script> import { servicesLoading } from '@/toolStation/' export default { data() { return { dialogVisible:false, } }, mounted() { }, methods: { sureFunc() { const loading = servicesLoading('.el-dialog', 'Loading', true) setTimeout(() => { () }, 2000); } }, } </script> <style lang="less" scoped> </style>
After encapsulation in the need to call on it, pay attention to the encapsulation of the first parameter: override the dom node to choose the right;
When we have more than one dialog on a page, nodes still use .el-dialog will obviously conflict, this time we can use v-if to solve this problem. If you do not want to use v-if, you can consider adding a class style to the dialog, such as adding a class named addCls, then the first parameter in the package can be written as .addCls .el-dialog, you can solve the problem.