Implementing a progress bar in Vue.js can be achieved using a combination of HTML, CSS, and JavaScript. Here's a simple example of how you can create a progress bar component:
ProgressBar.vue
:html<template>
<div class="progress-bar-container">
<div class="progress-bar" :style="{ width: progress + '%' }"></div>
</div>
</template>
<script>
export default {
props: {
value: {
type: Number,
required: true,
},
maxValue: {
type: Number,
default: 100,
},
},
computed: {
progress() {
return (this.value / this.maxValue) * 100;
},
},
};
</script>
<style scoped>
.progress-bar-container {
width: 100%;
height: 20px;
background-color: #ddd;
border-radius: 4px;
overflow: hidden;
}
.progress-bar {
height: 100%;
background-color: #4caf50;
transition: width 0.3s;
}
</style>
ProgressBar
component in your parent component or page where you want to show the progress bar:html<template>
<div>
<ProgressBar :value="currentProgress" :maxValue="100" />
<button @click="startProgress">Start Progress</button>
</div>
</template>
<script>
import ProgressBar from '@/components/ProgressBar.vue';
export default {
components: {
ProgressBar,
},
data() {
return {
currentProgress: 0,
};
},
methods: {
startProgress() {
// Simulate a process that increments the progress value
const interval = setInterval(() => {
this.currentProgress += 10;
if (this.currentProgress >= 100) {
clearInterval(interval);
}
}, 500);
},
},
};
</script>
In this example, the ProgressBar
component takes a value
prop to determine the current progress and a maxValue
prop to set the maximum progress value. The progress bar is updated based on these props, and you can trigger changes in the parent component using methods or events.
Adjust the styles and customization according to your application's design. This is a basic example, and you can extend it further based on your specific requirements.