Vue 3 进度栏
此前,我们首先要感谢那些愿意帮助全球开发商的开发商,特别是那些为开发公司做出贡献的开发商 hilongjw/vue-进步栏在这里,我继续从先前的开发中为vuejs版本3提供支持.
目录
演示
所需资源
- Vue.js (英语)
3.x
安装
# npm
$ npm install @aacassandra/vue3-progressbar
使用量
主语.js
import { createApp } from "vue";
import App from "./App.vue";
import router from "./router";
import VueProgressBar from "@aacassandra/vue3-progressbar";
const options = {
color: "#bffaf3",
failedColor: "#874b4b",
thickness: "5px",
transition: {
speed: "0.2s",
opacity: "0.6s",
termination: 300,
},
autoRevert: true,
location: "left",
inverse: false,
};
createApp(App)
.use(VueProgressBar, options)
.use(router)
.mount("#app");
构造选项
| 键 | 说明 | 默认 | 选项 |
|---|---|---|---|
color | 进度栏的颜色 | 'rgb(143, 255, 199)' | RGB HEX HSL HSV VEC |
failedColor | 负载失败时进度栏的颜色 | 'red' | RGB, (中文(简体) ), HEX, (中文(简体) ), HSL, (中文(简体) ), HSV, (中文(简体) ), VEC |
thickness | 进度栏的厚度 | '2px' | px, (中文(简体) ), em, (中文(简体) ), pt, (中文(简体) ), %, (中文(简体) ), vh, (中文(简体) ), vw |
transition | 过渡速度/不透明/进度栏终止 | {speed: '0.2s', opacity: '0.6s', termination: 300} | speed, (中文(简体) ), opacity, (中文(简体) ), termination |
autoRevert | 完成或失败时会自动返回临时颜色变化 | true | true, (中文(简体) ), false |
location | 更改进度栏的位置 | top | left, (中文(简体) ), right, (中文(简体) ), top, (中文(简体) ), bottom |
position | 更改进度栏的位置 | fixed | relative, (中文(简体) ), absolute, (中文(简体) ), fixed |
inverse | 倒转进度栏的方向 | false | true, (中文(简体) ), false |
autoFinish | 允许进程栏在接近100%时自动完成 | true | true, (中文(简体) ), false |
执行情况
应用vue
<template>
<div id="app">
<!-- for example router view -->
<router-view></router-view>
<!-- set progressbar -->
<vue-progress-bar></vue-progress-bar>
</div>
</template>
<script>
export default {
mounted() {
// [App.vue specific] When App.vue is finish loading finish the progress bar
this.$Progress.finish();
},
created() {
// [App.vue specific] When App.vue is first loaded start the progress bar
this.$Progress.start();
// hook the progress bar to start before we move router-view
this.$router.beforeEach((to, from, next) => {
// does the page we want to go to have a meta.progress object
if (to.meta.progress !== undefined) {
let meta = to.meta.progress;
// parse meta tags
this.$Progress.parseMeta(meta);
}
// start the progress bar
this.$Progress.start();
// continue to next page
next();
});
// hook the progress bar to finish after we've finished moving router-view
this.$router.afterEach((to, from) => {
// finish the progress bar
this.$Progress.finish();
});
},
};
</script>
自行车
export default [
{
path: "/achievement",
name: "achievement",
component: "./components/Achievement.vue",
meta: {
progress: {
func: [
{ call: "color", modifier: "temp", argument: "#ffb000" },
{ call: "fail", modifier: "temp", argument: "#6e0000" },
{ call: "location", modifier: "temp", argument: "top" },
{
call: "transition",
modifier: "temp",
argument: { speed: "1.5s", opacity: "0.6s", termination: 400 },
},
],
},
},
},
];
vue-router 元选项
| 调用 | 修改 | 参数 | 实例 |
|---|---|---|---|
| 颜色 | set, (中文(简体) ), temp | string | {call: 'color', modifier: 'temp', argument: '#ffb000'} |
| 失败 | set, (中文(简体) ), temp | string | {call: 'fail', modifier: 'temp', argument: '#ffb000'} |
| 地点 | set, (中文(简体) ), temp | string | {call: 'location', modifier: 'temp', argument: 'top'} |
| 过渡 | set, (中文(简体) ), temp | object | {call: 'transition', modifier: 'temp', argument: {speed: '0.6s', opacity: '0.6s', termination: 400}} |
方法
| 函数 | 说明 | 参数 | 实例 |
|---|---|---|---|
| 开始 | 启动进度栏加载 | N/A | this.$Progress.start() |
| 结束 | 完成进度栏加载 | N/A | this.$Progress.finish() |
| 失败 | 导致进度栏结束并失败 | N/A | this.$Progress.fail() |
| 增加 | 将进度栏增加一定百分比 | number: integer | this.$Progress.increase(number) |
| 减少 | 将进度栏减少一定百分比 | number: integer | this.$Progress.decrease(number) |
| 设定 | 设置进度栏% | number: integer | this.$Progress.set(number) |
| 设置失败颜色 | 导致失败颜色永久更改 | color: string | this.$Progress.setFailColor(color) |
| 设置颜色 | 使进度颜色永久更改 | color: string | this.$Progress.setColor(color) |
| 设置 | 使进度栏位置永久更改 | location: string | this.$Progress.setLocation(location) |
| 转换 | 使进度栏的过渡速度/不透明/终止永久更改 | transition: object | this.$Progress.setTransition(transition) |
| 临时故障颜色 | 导致失败颜色改变( 暂时) | color: string | this.$Progress.tempFailColor(color) |
| 临时颜色 | 使进度颜色发生变化(暂时) | color: string | this.$Progress.tempColor(color) |
| 温度 | 导致进度栏位置发生变化(暂时) | location: string | this.$Progress.tempLocation(location) |
| 临时过渡 | 导致进度栏位置发生变化(暂时) | transition: object | this.$Progress.tempTransition(transition) |
| 还原颜色 | 使临时设置的进度颜色返回到以前的颜色 | N/A | this.$Progress.revertColor() |
| 返回失败颜色 | 因为临时设定的失败颜色返回到以前的颜色 | N/A | this.$Progress.revertFailColor() |
| 回转 | 让临时设定的过渡恢复到以前的状态 | N/A | this.$Progress.revertTransition() |
| 还原 | 使临时设置的进度和/或失败颜色变为以前的颜色 | N/A | this.$Progress.revert() |
| 解析器 | 剖析进度元数据 | meta: object | this.$Progress.parseMeta(meta) |
实例
正在装入数据( Vue- 资源)
<script>
export default {
methods: {
test() {
this.$Progress.start();
this.$http
.jsonp(
"http://api.rottentomatoes.com/api/public/v1.0/lists/movies/in_theaters.json?apikey=7waqfqbprs7pajbz28mqf6vz"
)
.then(
(response) => {
this.$Progress.finish();
},
(response) => {
this.$Progress.fail();
}
);
},
},
};
</script>
通过 vue 实例(例如轴截取器)外部访问进度栏
主语.js
// main.js from Usage section
Vue.use(VueProgressBar, options);
export default new Vue({
// export the Vue instance
...App,
}).$mount("#app");
api-axios.js (英语)
import axios from "axios";
import app from "../main"; // import the instance
const instance = axios.create({
baseURL: "/api",
});
instance.interceptors.request.use((config) => {
app.$Progress.start(); // for every request start the progress
return config;
});
instance.interceptors.response.use((response) => {
app.$Progress.finish(); // finish when a response is received
return response;
});
export default instance; // export axios instance to be imported in your app
自由主义
MIT License
Copyright (c) 2020 Alauddin Afif Cassandra
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
见 更多 关于自由