当前位置:网站首页>自定义一个loading指令
自定义一个loading指令
2022-07-02 16:01:00 【imkaifan】
loading.vue 组件
<template>
<div class="loading-wrapper">
<div class="loading-content">
<p class="title">{
{
title }}</p>
</div>
</div>
</template>
<script>
export default {
data() {
return {
title: '正在加载中...' };
}
};
</script>
<style lang="less" scoped>
.loading-wrapper {
// width: 100%;
// height: 100%;
// background: red;
position: absolute;
top: 50%;
left: 50%;
transform: translate3d(-50%, -50%, 0);
.loading-content {
width: 100%;
text-align: center;
.title {
line-height: 20px;
font-size: 12px;
margin: 0;
}
}
}
</style>
loading.js 指令核心代码
import Vue from 'vue';
import MyLoading from './loading.vue';
const myLoading = {
inserted(el, binding) {
console.log('自定义指令', el, binding);
const Loading = Vue.extend(MyLoading);
const loading = new Loading().$mount();
console.log('loading', loading);
el.instance = loading;
if (binding.value) {
append(el);
}
},
update(el, binding) {
if (binding.value !== binding.oldValue) {
binding.value ? append(el) : remove(el);
}
}
};
function append(el) {
console.log('自定义指令el', el.instance.$el);
el.appendChild(el.instance.$el);
}
function remove(el) {
el.removeChild(el.instance.$el);
}
export default myLoading;



main.js 去注册 注册指令
import myLoading from './view/contact/components/loading.js';
Vue.directive('myLoading', myLoading);
边栏推荐
- [nonlinear control theory]7_ High gain and High Frequency
- Platform management background and merchant menu resource management: merchant role management design
- MySQL --- 数据库的基本概念
- Wasserstein Slim GAIN with Clipping Penalty(WSGAIN-CP)介绍及代码实现——基于生成对抗网络的缺失数据填补
- Tips for self defined packaging of Yingguang SCM 003 burner
- HDU - 1114 Piggy Bank (full backpack)
- 【网络是怎么连接的】第四章 探索接入网和网络运营商
- Keras深度学习实战——基于VGG19模型实现性别分类
- uva1169
- 松翰SN8P2511 SOP8单片机 可代烧录 提供单片机方案开发 单片机解密
猜你喜欢
![[nonlinear control theory]7_ High gain and High Frequency](/img/e5/6c5ca4a89c97d9613cddccb281b35b.png)
[nonlinear control theory]7_ High gain and High Frequency

Chapter 15 string localization and message Dictionary (1)

科班出身,面试小公司都进不去

chrome瀏覽器快速訪問stackoverflow

VirtualLab基础实验教程-7.偏振(2)

【目标跟踪】|数据集汇总

Taiwan Feiling fm8pb513b MCU provides MCU program development product design

Use of nexttile function in MATLAB

ORA-19838 -- 恢复控制文件到备库

Modbus协议通信异常
随机推荐
Platform management background and merchant menu resource management: merchant role management design
Daily question - xiaolele changes the number
【网络是怎样连接的】第六章 请求到达服务器以及响应给客户端(完结)
This "architect growth note" made 300 people successfully change jobs and enter the big factory, with an annual salary of 50W
Linux中,mysql设置job任务自动启动
PHP gets the number of days, hours, minutes and seconds between the two timestamps
Two pieces of nature a day! Duan Fengfeng, an alumnus of the University of science and technology of China, was the third Chinese winner of the belby medal
The price is only 40 yuan. Pico development board of raspberry pie is added with WiFi module, and it is out of stock as soon as it comes into the market
详解Kubernetes网络模型
Use of nexttile function in MATLAB
【目标跟踪】|SiamFC
Modbus protocol communication exception
透过华为军团看科技之变(六):智慧公路
王者荣耀商城异地多活架构设计
Huimang micro IO MCU ft60f011a-rb
win10 kms activator
辉芒微IO单片机FT60F010A-URT
每日一题——倒置字符串
[how is the network connected] Chapter 4 explores access networks and network operators
【历史上的今天】7 月 2 日:BitTorrent 问世;商业系统 Linspire 被收购;索尼部署 PlayStation Now