在src/components目录下创建自己的组件文件夹,例zkxUI

例如loading组件 需注意name属性命名组件 例zkxLoading


loading组件代码
<template>
<transition name="zkxLoading" v-if="visible">
<section>
<div class="loading">
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
</div>
</section>
</transition>
</template>
<script>
export default {
name: "zkxLoading",
props: ["visible"],
data() {
return {};
},
methods: {}
};
</script>
<style scoped lang="scss">
.fade-enter-active,
.fade-leave-active {
transition: opacity 0.5s;
}
.fade-enter, .fade-leave-to {
opacity: 0;
}
section {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(0, 0, 0, 0.3);
z-index: 999;
display: flex;
align-items: center;
justify-content: center;
}
.loading {
width: 100%;
text-align: center;
}
.loading span {
display: inline-block;
width: 8px;
height: 100%;
border-radius: 4px;
background: lightgreen;
-webkit-animation: load 1s ease infinite;
margin-left: 5px;
}
@-webkit-keyframes load {
0%,
100% {
height: 40px;
background: lightgreen;
}
50% {
height: 70px;
margin: -15px 0;
background: lightblue;
}
}
.loading span:nth-child(2) {
-webkit-animation-delay: 0.2s;
}
.loading span:nth-child(3) {
-webkit-animation-delay: 0.4s;
}
.loading span:nth-child(4) {
-webkit-animation-delay: 0.6s;
}
.loading span:nth-child(5) {
-webkit-animation-delay: 0.8s;
}
</style>
组件注册代码 index.js

import zkxLoading from "./zkx-loading"
const components = [
zkxLoading
]
const install = function(Vue) {
components.forEach(component => {
Vue.component(component.name, component);
});
};
export default install
在main.js里引入

在页面中直接使用
