进度线

v-progress-lineear 组件用于将数据直观传输给用户。它们也可以表示一个不确定的数量,如加载或处理。

用例

最简单的形式,v-progress-linear 显示一个水平进度条。使用 value 属性来控制进度。

template


  1. <template>
  2. <v-progress-linear value="15"></v-progress-linear>
  3. </template>

Linear(进度线) - 图1

API

从下面选择您想要的组件,并查看可用的属性、插槽、事件和函数。

Linear(进度线) - 图2

实战场

template script


  1. <template>
  2. <v-row justify="center" align="center">
  3. <v-container>
  4. <v-progress-linear
  5. :active="active"
  6. :background-opacity="opacity"
  7. :bottom="bottom"
  8. :buffer-value="buffer"
  9. :height="height"
  10. :indeterminate="indeterminate"
  11. :query="query"
  12. :rounded="rounded"
  13. :stream="stream"
  14. :striped="striped"
  15. :top="top"
  16. :value="value"
  17. color="light-blue"
  18. ></v-progress-linear>
  19. </v-container>
  20. <v-row>
  21. <v-col cols="12" md="6" lg="3">
  22. <v-text-field
  23. v-model="buffer"
  24. class="mx-4"
  25. label="Buffer"
  26. max="100"
  27. min="1"
  28. step="1"
  29. style="width: 125px"
  30. type="number"
  31. @keydown="false"
  32. ></v-text-field>
  33. </v-col>
  34. <v-col cols="12" md="6" lg="3">
  35. <v-text-field
  36. v-model="height"
  37. class="mx-4"
  38. label="Height - px"
  39. max="100"
  40. min="1"
  41. step="1"
  42. style="width: 125px"
  43. type="number"
  44. @keydown="false"
  45. ></v-text-field>
  46. </v-col>
  47. <v-col cols="12" md="6" lg="3">
  48. <v-text-field
  49. v-model="opacity"
  50. class="mx-4"
  51. label="Opacity"
  52. max="1"
  53. min="0"
  54. step=".01"
  55. style="width: 125px"
  56. type="number"
  57. @keydown="false"
  58. ></v-text-field>
  59. </v-col>
  60. <v-col cols="12" md="6" lg="3">
  61. <v-text-field
  62. v-model="value"
  63. class="mx-4"
  64. label="Value - %"
  65. max="100"
  66. min="1"
  67. step="1"
  68. style="width: 125px"
  69. type="number"
  70. @keydown="false"
  71. ></v-text-field>
  72. </v-col>
  73. <v-col cols="6" md="3">
  74. <v-switch v-model="active" label="Toggle active" class="mx-4"></v-switch>
  75. </v-col>
  76. <v-col cols="6" md="3">
  77. <v-switch v-model="bottom" label="Toggle bottom" class="mx-4"></v-switch>
  78. </v-col>
  79. <v-col cols="6" md="3">
  80. <v-switch v-model="indeterminate" label="Toggle indeterminate" class="mx-4"></v-switch>
  81. </v-col>
  82. <v-col cols="6" md="3">
  83. <v-switch v-model="query" label="Toggle query" class="mx-4"></v-switch>
  84. </v-col>
  85. <v-col cols="6" md="3">
  86. <v-switch v-model="rounded" label="Toggle rounded" class="mx-4"></v-switch>
  87. </v-col>
  88. <v-col cols="6" md="3">
  89. <v-switch v-model="stream" label="Toggle stream" class="mx-4"></v-switch>
  90. </v-col>
  91. <v-col cols="6" md="3">
  92. <v-switch v-model="striped" label="Toggle striped" class="mx-4"></v-switch>
  93. </v-col>
  94. <v-col cols="6" md="3">
  95. <v-switch v-model="top" label="Toggle top" class="mx-4"></v-switch>
  96. </v-col>
  97. </v-row>
  98. </v-row>
  99. </template>
  1. <script>
  2. export default {
  3. data: () => ({
  4. absolute: false,
  5. active: true,
  6. opacity: 0.3,
  7. bottom: false,
  8. buffer: 100,
  9. fixed: false,
  10. height: 4,
  11. indeterminate: false,
  12. query: false,
  13. rounded: false,
  14. stream: false,
  15. striped: false,
  16. top: false,
  17. value: 25,
  18. }),
  19. }
  20. </script>

Linear(进度线) - 图3

示例

下面是一些简单到复杂的例子。

定值线条

进度线条组件可以有一个由 v-model 修改的确定性状态。

template script


  1. <template>
  2. <div>
  3. <v-progress-linear
  4. v-model="valueDeterminate"
  5. color="deep-purple accent-4"
  6. ></v-progress-linear>
  7. <br>
  8. <v-progress-linear
  9. v-model="valueDeterminate"
  10. color="pink"
  11. ></v-progress-linear>
  12. <br>
  13. <v-progress-linear
  14. v-model="valueDeterminate"
  15. color="indigo darken-2"
  16. ></v-progress-linear>
  17. <br>
  18. <v-progress-linear
  19. v-model="valueDeterminate"
  20. color="amber"
  21. ></v-progress-linear>
  22. </div>
  23. </template>
  1. <script>
  2. export default {
  3. data () {
  4. return {
  5. valueDeterminate: 50,
  6. }
  7. },
  8. }
  9. </script>

Linear(进度线) - 图4

不定线条

使用 indeterminate 属性, v-progress-linear 持续不断的动画。

template


  1. <template>
  2. <div>
  3. <v-progress-linear
  4. indeterminate
  5. color="yellow darken-2"
  6. ></v-progress-linear>
  7. <br>
  8. <v-progress-linear
  9. indeterminate
  10. color="green"
  11. ></v-progress-linear>
  12. <br>
  13. <v-progress-linear
  14. indeterminate
  15. color="teal"
  16. ></v-progress-linear>
  17. <br>
  18. <v-progress-linear
  19. indeterminate
  20. color="cyan"
  21. ></v-progress-linear>
  22. </div>
  23. </template>

Linear(进度线) - 图5

缓冲

缓冲区状态同时表示两个值。 主值由 v-model 控制,而缓冲区由 buffer-value 属性控制。

template script


  1. <template>
  2. <div>
  3. <v-progress-linear
  4. v-model="value"
  5. :buffer-value="bufferValue"
  6. ></v-progress-linear>
  7. <br>
  8. <v-progress-linear
  9. v-model="value"
  10. :buffer-value="bufferValue"
  11. color="purple"
  12. ></v-progress-linear>
  13. <br>
  14. <v-progress-linear
  15. v-model="value"
  16. :buffer-value="bufferValue"
  17. color="red lighten-2"
  18. ></v-progress-linear>
  19. <br>
  20. <v-progress-linear
  21. v-model="value"
  22. :buffer-value="bufferValue"
  23. color="black"
  24. ></v-progress-linear>
  25. </div>
  26. </template>
  1. <script>
  2. export default {
  3. data () {
  4. return {
  5. value: 10,
  6. bufferValue: 20,
  7. interval: 0,
  8. }
  9. },
  10. watch: {
  11. value (val) {
  12. if (val < 100) return
  13. this.value = 0
  14. this.bufferValue = 10
  15. this.startBuffer()
  16. },
  17. },
  18. mounted () {
  19. this.startBuffer()
  20. },
  21. beforeDestroy () {
  22. clearInterval(this.interval)
  23. },
  24. methods: {
  25. startBuffer () {
  26. clearInterval(this.interval)
  27. this.interval = setInterval(() => {
  28. this.value += Math.random() * (15 - 5) + 5
  29. this.bufferValue += Math.random() * (15 - 5) + 6
  30. }, 2000)
  31. },
  32. },
  33. }
  34. </script>

Linear(进度线) - 图6

查询不确定和确定

query 属性设置为 true 时,query 状态由不确定性的真实性控制 。

template script


  1. <template>
  2. <div style="min-height: 4px;">
  3. <v-progress-linear
  4. v-model="value"
  5. :active="show"
  6. :indeterminate="query"
  7. :query="true"
  8. ></v-progress-linear>
  9. </div>
  10. </template>
  1. <script>
  2. export default {
  3. data () {
  4. return {
  5. value: 0,
  6. query: false,
  7. show: true,
  8. interval: 0,
  9. }
  10. },
  11. mounted () {
  12. this.queryAndIndeterminate()
  13. },
  14. beforeDestroy () {
  15. clearInterval(this.interval)
  16. },
  17. methods: {
  18. queryAndIndeterminate () {
  19. this.query = true
  20. this.show = true
  21. this.value = 0
  22. setTimeout(() => {
  23. this.query = false
  24. this.interval = setInterval(() => {
  25. if (this.value === 100) {
  26. clearInterval(this.interval)
  27. this.show = false
  28. return setTimeout(this.queryAndIndeterminate, 2000)
  29. }
  30. this.value += 25
  31. }, 1000)
  32. }, 2500)
  33. },
  34. },
  35. }
  36. </script>

Linear(进度线) - 图7

自定义颜色

您还可以使用属性 colorbackground-color 设置颜色。

template


  1. <template>
  2. <div>
  3. <v-progress-linear
  4. background-color="pink lighten-3"
  5. color="pink lighten-1"
  6. value="15"
  7. ></v-progress-linear>
  8. <br>
  9. <v-progress-linear
  10. background-color="blue-grey"
  11. color="lime"
  12. value="30"
  13. ></v-progress-linear>
  14. <br>
  15. <v-progress-linear
  16. background-color="success"
  17. color="error"
  18. value="45"
  19. ></v-progress-linear>
  20. </div>
  21. </template>

Linear(进度线) - 图8

圆角

rounded 属性是一种替代样式,为 v-progress-linear 组件添加了边框半径。

template


  1. <template>
  2. <div>
  3. <v-progress-linear
  4. color="red darken-2"
  5. rounded
  6. value="100"
  7. ></v-progress-linear>
  8. <br>
  9. <v-progress-linear
  10. color="indigo"
  11. rounded
  12. value="100"
  13. ></v-progress-linear>
  14. <br>
  15. <v-progress-linear
  16. color="teal"
  17. rounded
  18. value="100"
  19. ></v-progress-linear>
  20. <br>
  21. <v-progress-linear
  22. color="cyan darken-2"
  23. rounded
  24. value="100"
  25. ></v-progress-linear>
  26. </div>
  27. </template>

Linear(进度线) - 图9

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-valuevalue 的任何组合来实现您的设计。

template


  1. <template>
  2. <div>
  3. <v-progress-linear
  4. color="red lighten-2"
  5. buffer-value="0"
  6. stream
  7. ></v-progress-linear>
  8. <br>
  9. <v-progress-linear
  10. color="teal"
  11. buffer-value="0"
  12. value="20"
  13. stream
  14. ></v-progress-linear>
  15. <br>
  16. <v-progress-linear
  17. buffer-value="50"
  18. stream
  19. color="cyan"
  20. ></v-progress-linear>
  21. <br>
  22. <v-progress-linear
  23. buffer-value="60"
  24. value="40"
  25. stream
  26. color="orange"
  27. ></v-progress-linear>
  28. </div>
  29. </template>

Linear(进度线) - 图10

有条纹的

这将在 v-progress-linear 的值部分上应用条纹背景。

template


  1. <template>
  2. <div>
  3. <v-progress-linear
  4. color="light-blue"
  5. height="10"
  6. value="10"
  7. striped
  8. ></v-progress-linear>
  9. <br>
  10. <v-progress-linear
  11. color="light-green darken-4"
  12. height="10"
  13. value="20"
  14. striped
  15. ></v-progress-linear>
  16. <br>
  17. <v-progress-linear
  18. height="10"
  19. value="45"
  20. striped
  21. color="lime"
  22. ></v-progress-linear>
  23. <br>
  24. <v-progress-linear
  25. value="60"
  26. height="10"
  27. striped
  28. color="deep-orange"
  29. ></v-progress-linear>
  30. </div>
  31. </template>

Linear(进度线) - 图11

工具栏加载器

使用 absolute 属性,我们可以将 v-progress-linear 组件定位在 v-toolbar 的底部。我们还使用了 active 属性来控制进度的可见性。

template script


  1. <template>
  2. <v-card
  3. class="mx-auto mt-6"
  4. width="344"
  5. >
  6. <v-system-bar>
  7. <v-spacer></v-spacer>
  8. <v-icon>mdi-square</v-icon>
  9. <v-icon>mdi-circle</v-icon>
  10. <v-icon>mdi-triangle</v-icon>
  11. </v-system-bar>
  12. <v-toolbar>
  13. <v-btn icon>
  14. <v-icon>mdi-arrow-left</v-icon>
  15. </v-btn>
  16. <v-toolbar-title>My Recipes</v-toolbar-title>
  17. <v-progress-linear
  18. :active="loading"
  19. :indeterminate="loading"
  20. absolute
  21. bottom
  22. color="deep-purple accent-4"
  23. ></v-progress-linear>
  24. <v-spacer></v-spacer>
  25. <v-btn icon>
  26. <v-icon>mdi-magnify</v-icon>
  27. </v-btn>
  28. <v-btn icon>
  29. <v-icon>mdi-dots-vertical</v-icon>
  30. </v-btn>
  31. </v-toolbar>
  32. <v-container style="height: 282px;">
  33. <v-row
  34. class="fill-height"
  35. align="center"
  36. justify="center"
  37. >
  38. <v-scale-transition>
  39. <div
  40. v-if="!loading"
  41. class="text-center"
  42. >
  43. <v-btn
  44. color="primary"
  45. @click="loading = true"
  46. >Start loading</v-btn>
  47. </div>
  48. </v-scale-transition>
  49. </v-row>
  50. </v-container>
  51. </v-card>
  52. </template>
  1. <script>
  2. export default {
  3. data: () => ({
  4. loading: false,
  5. }),
  6. watch: {
  7. loading (val) {
  8. if (!val) return
  9. setTimeout(() => (this.loading = false), 3000)
  10. },
  11. },
  12. }
  13. </script>

Linear(进度线) - 图12

文件加载器

v-progress-linear 组件有助于向用户解释他们正在等待响应。

template


  1. <template>
  2. <v-card
  3. class="mx-auto"
  4. max-width="344"
  5. >
  6. <v-toolbar
  7. color="deep-purple accent-4"
  8. dark
  9. prominent
  10. >
  11. <v-app-bar-nav-icon></v-app-bar-nav-icon>
  12. <v-toolbar-title>My Files</v-toolbar-title>
  13. <v-btn
  14. absolute
  15. bottom
  16. color="white"
  17. fab
  18. left
  19. light
  20. >
  21. <v-icon>mdi-plus</v-icon>
  22. </v-btn>
  23. <v-spacer></v-spacer>
  24. <v-btn icon>
  25. <v-icon>mdi-share-variant</v-icon>
  26. </v-btn>
  27. <v-btn icon>
  28. <v-icon>mdi-magnify</v-icon>
  29. </v-btn>
  30. <v-btn icon>
  31. <v-icon>mdi-dots-vertical</v-icon>
  32. </v-btn>
  33. </v-toolbar>
  34. <v-container style="height: 400px;">
  35. <v-row
  36. class="fill-height"
  37. align-content="center"
  38. justify="center"
  39. >
  40. <v-col
  41. class="subtitle-1 text-center"
  42. cols="12"
  43. >
  44. Getting your files
  45. </v-col>
  46. <v-col cols="6">
  47. <v-progress-linear
  48. color="deep-purple accent-4"
  49. indeterminate
  50. rounded
  51. height="6"
  52. ></v-progress-linear>
  53. </v-col>
  54. </v-row>
  55. </v-container>
  56. </v-card>
  57. </template>

Linear(进度线) - 图13

插槽

使用 v-model 时,v-progress-linear 组件将响应用户输入。 您可以使用默认插槽或绑定本地模型以显示进度内部。 如果要在线性组件上寻找高级功能,请查看 v-slider

template script


  1. <template>
  2. <div>
  3. <v-progress-linear
  4. v-model="power"
  5. color="amber"
  6. height="25"
  7. reactive
  8. ></v-progress-linear>
  9. <br>
  10. <v-progress-linear
  11. v-model="skill"
  12. color="blue-grey"
  13. height="25"
  14. reactive
  15. >
  16. <template v-slot="{ value }">
  17. <strong>{{ Math.ceil(value) }}%</strong>
  18. </template>
  19. </v-progress-linear>
  20. <br>
  21. <v-progress-linear
  22. v-model="knowledge"
  23. height="25"
  24. reactive
  25. >
  26. <strong>{{ Math.ceil(knowledge) }}%</strong>
  27. </v-progress-linear>
  28. </div>
  29. </template>
  1. <script>
  2. export default {
  3. data: () => ({
  4. skill: 20,
  5. knowledge: 33,
  6. power: 78,
  7. }),
  8. }
  9. </script>

Linear(进度线) - 图14