进度线
v-progress-lineear
组件用于将数据直观传输给用户。它们也可以表示一个不确定的数量,如加载或处理。
用例
最简单的形式,v-progress-linear
显示一个水平进度条。使用 value
属性来控制进度。
template
<template>
<v-progress-linear value="15"></v-progress-linear>
</template>
API
从下面选择您想要的组件,并查看可用的属性、插槽、事件和函数。
实战场
template script
<template>
<v-row justify="center" align="center">
<v-container>
<v-progress-linear
:active="active"
:background-opacity="opacity"
:bottom="bottom"
:buffer-value="buffer"
:height="height"
:indeterminate="indeterminate"
:query="query"
:rounded="rounded"
:stream="stream"
:striped="striped"
:top="top"
:value="value"
color="light-blue"
></v-progress-linear>
</v-container>
<v-row>
<v-col cols="12" md="6" lg="3">
<v-text-field
v-model="buffer"
class="mx-4"
label="Buffer"
max="100"
min="1"
step="1"
style="width: 125px"
type="number"
@keydown="false"
></v-text-field>
</v-col>
<v-col cols="12" md="6" lg="3">
<v-text-field
v-model="height"
class="mx-4"
label="Height - px"
max="100"
min="1"
step="1"
style="width: 125px"
type="number"
@keydown="false"
></v-text-field>
</v-col>
<v-col cols="12" md="6" lg="3">
<v-text-field
v-model="opacity"
class="mx-4"
label="Opacity"
max="1"
min="0"
step=".01"
style="width: 125px"
type="number"
@keydown="false"
></v-text-field>
</v-col>
<v-col cols="12" md="6" lg="3">
<v-text-field
v-model="value"
class="mx-4"
label="Value - %"
max="100"
min="1"
step="1"
style="width: 125px"
type="number"
@keydown="false"
></v-text-field>
</v-col>
<v-col cols="6" md="3">
<v-switch v-model="active" label="Toggle active" class="mx-4"></v-switch>
</v-col>
<v-col cols="6" md="3">
<v-switch v-model="bottom" label="Toggle bottom" class="mx-4"></v-switch>
</v-col>
<v-col cols="6" md="3">
<v-switch v-model="indeterminate" label="Toggle indeterminate" class="mx-4"></v-switch>
</v-col>
<v-col cols="6" md="3">
<v-switch v-model="query" label="Toggle query" class="mx-4"></v-switch>
</v-col>
<v-col cols="6" md="3">
<v-switch v-model="rounded" label="Toggle rounded" class="mx-4"></v-switch>
</v-col>
<v-col cols="6" md="3">
<v-switch v-model="stream" label="Toggle stream" class="mx-4"></v-switch>
</v-col>
<v-col cols="6" md="3">
<v-switch v-model="striped" label="Toggle striped" class="mx-4"></v-switch>
</v-col>
<v-col cols="6" md="3">
<v-switch v-model="top" label="Toggle top" class="mx-4"></v-switch>
</v-col>
</v-row>
</v-row>
</template>
<script>
export default {
data: () => ({
absolute: false,
active: true,
opacity: 0.3,
bottom: false,
buffer: 100,
fixed: false,
height: 4,
indeterminate: false,
query: false,
rounded: false,
stream: false,
striped: false,
top: false,
value: 25,
}),
}
</script>
示例
下面是一些简单到复杂的例子。
定值线条
进度线条组件可以有一个由 v-model
修改的确定性状态。
template script
<template>
<div>
<v-progress-linear
v-model="valueDeterminate"
color="deep-purple accent-4"
></v-progress-linear>
<br>
<v-progress-linear
v-model="valueDeterminate"
color="pink"
></v-progress-linear>
<br>
<v-progress-linear
v-model="valueDeterminate"
color="indigo darken-2"
></v-progress-linear>
<br>
<v-progress-linear
v-model="valueDeterminate"
color="amber"
></v-progress-linear>
</div>
</template>
<script>
export default {
data () {
return {
valueDeterminate: 50,
}
},
}
</script>
不定线条
使用 indeterminate
属性, v-progress-linear
持续不断的动画。
template
<template>
<div>
<v-progress-linear
indeterminate
color="yellow darken-2"
></v-progress-linear>
<br>
<v-progress-linear
indeterminate
color="green"
></v-progress-linear>
<br>
<v-progress-linear
indeterminate
color="teal"
></v-progress-linear>
<br>
<v-progress-linear
indeterminate
color="cyan"
></v-progress-linear>
</div>
</template>
缓冲
缓冲区状态同时表示两个值。 主值由 v-model
控制,而缓冲区由 buffer-value
属性控制。
template script
<template>
<div>
<v-progress-linear
v-model="value"
:buffer-value="bufferValue"
></v-progress-linear>
<br>
<v-progress-linear
v-model="value"
:buffer-value="bufferValue"
color="purple"
></v-progress-linear>
<br>
<v-progress-linear
v-model="value"
:buffer-value="bufferValue"
color="red lighten-2"
></v-progress-linear>
<br>
<v-progress-linear
v-model="value"
:buffer-value="bufferValue"
color="black"
></v-progress-linear>
</div>
</template>
<script>
export default {
data () {
return {
value: 10,
bufferValue: 20,
interval: 0,
}
},
watch: {
value (val) {
if (val < 100) return
this.value = 0
this.bufferValue = 10
this.startBuffer()
},
},
mounted () {
this.startBuffer()
},
beforeDestroy () {
clearInterval(this.interval)
},
methods: {
startBuffer () {
clearInterval(this.interval)
this.interval = setInterval(() => {
this.value += Math.random() * (15 - 5) + 5
this.bufferValue += Math.random() * (15 - 5) + 6
}, 2000)
},
},
}
</script>
查询不确定和确定
query
属性设置为 true 时,query
状态由不确定性的真实性控制 。
template script
<template>
<div style="min-height: 4px;">
<v-progress-linear
v-model="value"
:active="show"
:indeterminate="query"
:query="true"
></v-progress-linear>
</div>
</template>
<script>
export default {
data () {
return {
value: 0,
query: false,
show: true,
interval: 0,
}
},
mounted () {
this.queryAndIndeterminate()
},
beforeDestroy () {
clearInterval(this.interval)
},
methods: {
queryAndIndeterminate () {
this.query = true
this.show = true
this.value = 0
setTimeout(() => {
this.query = false
this.interval = setInterval(() => {
if (this.value === 100) {
clearInterval(this.interval)
this.show = false
return setTimeout(this.queryAndIndeterminate, 2000)
}
this.value += 25
}, 1000)
}, 2500)
},
},
}
</script>
自定义颜色
您还可以使用属性 color
和 background-color
设置颜色。
template
<template>
<div>
<v-progress-linear
background-color="pink lighten-3"
color="pink lighten-1"
value="15"
></v-progress-linear>
<br>
<v-progress-linear
background-color="blue-grey"
color="lime"
value="30"
></v-progress-linear>
<br>
<v-progress-linear
background-color="success"
color="error"
value="45"
></v-progress-linear>
</div>
</template>
圆角
rounded
属性是一种替代样式,为 v-progress-linear
组件添加了边框半径。
template
<template>
<div>
<v-progress-linear
color="red darken-2"
rounded
value="100"
></v-progress-linear>
<br>
<v-progress-linear
color="indigo"
rounded
value="100"
></v-progress-linear>
<br>
<v-progress-linear
color="teal"
rounded
value="100"
></v-progress-linear>
<br>
<v-progress-linear
color="cyan darken-2"
rounded
value="100"
></v-progress-linear>
</div>
</template>
Status Page
You can check the status of the documentation any time on our OhDear! uptime page.
ads by Vuetify
](https://status.vuetifyjs.com?ref=vuetifyjs.com)
流
stream
属性与 buffer-value
一起工作,向用户传达正在进行某些操作。您可以使用 buffer-value
和 value
的任何组合来实现您的设计。
template
<template>
<div>
<v-progress-linear
color="red lighten-2"
buffer-value="0"
stream
></v-progress-linear>
<br>
<v-progress-linear
color="teal"
buffer-value="0"
value="20"
stream
></v-progress-linear>
<br>
<v-progress-linear
buffer-value="50"
stream
color="cyan"
></v-progress-linear>
<br>
<v-progress-linear
buffer-value="60"
value="40"
stream
color="orange"
></v-progress-linear>
</div>
</template>
有条纹的
这将在 v-progress-linear
的值部分上应用条纹背景。
template
<template>
<div>
<v-progress-linear
color="light-blue"
height="10"
value="10"
striped
></v-progress-linear>
<br>
<v-progress-linear
color="light-green darken-4"
height="10"
value="20"
striped
></v-progress-linear>
<br>
<v-progress-linear
height="10"
value="45"
striped
color="lime"
></v-progress-linear>
<br>
<v-progress-linear
value="60"
height="10"
striped
color="deep-orange"
></v-progress-linear>
</div>
</template>
工具栏加载器
使用 absolute
属性,我们可以将 v-progress-linear
组件定位在 v-toolbar
的底部。我们还使用了 active
属性来控制进度的可见性。
template script
<template>
<v-card
class="mx-auto mt-6"
width="344"
>
<v-system-bar>
<v-spacer></v-spacer>
<v-icon>mdi-square</v-icon>
<v-icon>mdi-circle</v-icon>
<v-icon>mdi-triangle</v-icon>
</v-system-bar>
<v-toolbar>
<v-btn icon>
<v-icon>mdi-arrow-left</v-icon>
</v-btn>
<v-toolbar-title>My Recipes</v-toolbar-title>
<v-progress-linear
:active="loading"
:indeterminate="loading"
absolute
bottom
color="deep-purple accent-4"
></v-progress-linear>
<v-spacer></v-spacer>
<v-btn icon>
<v-icon>mdi-magnify</v-icon>
</v-btn>
<v-btn icon>
<v-icon>mdi-dots-vertical</v-icon>
</v-btn>
</v-toolbar>
<v-container style="height: 282px;">
<v-row
class="fill-height"
align="center"
justify="center"
>
<v-scale-transition>
<div
v-if="!loading"
class="text-center"
>
<v-btn
color="primary"
@click="loading = true"
>Start loading</v-btn>
</div>
</v-scale-transition>
</v-row>
</v-container>
</v-card>
</template>
<script>
export default {
data: () => ({
loading: false,
}),
watch: {
loading (val) {
if (!val) return
setTimeout(() => (this.loading = false), 3000)
},
},
}
</script>
文件加载器
v-progress-linear
组件有助于向用户解释他们正在等待响应。
template
<template>
<v-card
class="mx-auto"
max-width="344"
>
<v-toolbar
color="deep-purple accent-4"
dark
prominent
>
<v-app-bar-nav-icon></v-app-bar-nav-icon>
<v-toolbar-title>My Files</v-toolbar-title>
<v-btn
absolute
bottom
color="white"
fab
left
light
>
<v-icon>mdi-plus</v-icon>
</v-btn>
<v-spacer></v-spacer>
<v-btn icon>
<v-icon>mdi-share-variant</v-icon>
</v-btn>
<v-btn icon>
<v-icon>mdi-magnify</v-icon>
</v-btn>
<v-btn icon>
<v-icon>mdi-dots-vertical</v-icon>
</v-btn>
</v-toolbar>
<v-container style="height: 400px;">
<v-row
class="fill-height"
align-content="center"
justify="center"
>
<v-col
class="subtitle-1 text-center"
cols="12"
>
Getting your files
</v-col>
<v-col cols="6">
<v-progress-linear
color="deep-purple accent-4"
indeterminate
rounded
height="6"
></v-progress-linear>
</v-col>
</v-row>
</v-container>
</v-card>
</template>
插槽
使用 v-model
时,v-progress-linear
组件将响应用户输入。 您可以使用默认插槽或绑定本地模型以显示进度内部。 如果要在线性组件上寻找高级功能,请查看 v-slider。
template script
<template>
<div>
<v-progress-linear
v-model="power"
color="amber"
height="25"
reactive
></v-progress-linear>
<br>
<v-progress-linear
v-model="skill"
color="blue-grey"
height="25"
reactive
>
<template v-slot="{ value }">
<strong>{{ Math.ceil(value) }}%</strong>
</template>
</v-progress-linear>
<br>
<v-progress-linear
v-model="knowledge"
height="25"
reactive
>
<strong>{{ Math.ceil(knowledge) }}%</strong>
</v-progress-linear>
</div>
</template>
<script>
export default {
data: () => ({
skill: 20,
knowledge: 33,
power: 78,
}),
}
</script>