步骤条
v-stepper
组件用于显示步骤进度。
用例
一个步骤组件适用于多种场景,包括购物车、创建记录等等。
template script
<template>
<v-stepper v-model="e1">
<v-stepper-header>
<v-stepper-step :complete="e1 > 1" step="1">Name of step 1</v-stepper-step>
<v-divider></v-divider>
<v-stepper-step :complete="e1 > 2" step="2">Name of step 2</v-stepper-step>
<v-divider></v-divider>
<v-stepper-step step="3">Name of step 3</v-stepper-step>
</v-stepper-header>
<v-stepper-items>
<v-stepper-content step="1">
<v-card
class="mb-12"
color="grey lighten-1"
height="200px"
></v-card>
<v-btn
color="primary"
@click="e1 = 2"
>
Continue
</v-btn>
<v-btn text>Cancel</v-btn>
</v-stepper-content>
<v-stepper-content step="2">
<v-card
class="mb-12"
color="grey lighten-1"
height="200px"
></v-card>
<v-btn
color="primary"
@click="e1 = 3"
>
Continue
</v-btn>
<v-btn text>Cancel</v-btn>
</v-stepper-content>
<v-stepper-content step="3">
<v-card
class="mb-12"
color="grey lighten-1"
height="200px"
></v-card>
<v-btn
color="primary"
@click="e1 = 1"
>
Continue
</v-btn>
<v-btn text>Cancel</v-btn>
</v-stepper-content>
</v-stepper-items>
</v-stepper>
</template>
<script>
export default {
data () {
return {
e1: 1,
}
},
}
</script>
API
从下面选择您想要的组件,并查看可用的属性、插槽、事件和函数。
实战场
template script
<template>
<div>
<v-row justify="space-around">
<v-col cols="12">
<v-slider v-model="steps" label="Steps" min="2" max="20"></v-slider>
</v-col>
<v-switch v-model="vertical" label="Vertical"></v-switch>
<v-switch v-model="altLabels" label="altLabels"></v-switch>
<v-switch v-model="editable" label="Editable"></v-switch>
</v-row>
<v-stepper
v-model="e1"
:vertical="vertical"
:alt-labels="altLabels"
>
<template v-if="vertical">
<template v-for="n in steps">
<v-stepper-step
:key="`${n}-step`"
:complete="e1 > n"
:step="n"
:editable="editable"
>
Step {{ n }}
</v-stepper-step>
<v-stepper-content
:key="`${n}-content`"
:step="n"
>
<v-card
class="mb-12"
color="grey lighten-1"
height="200px"
></v-card>
<v-btn
color="primary"
@click="nextStep(n)"
>
Continue
</v-btn>
<v-btn text>Cancel</v-btn>
</v-stepper-content>
</template>
</template>
<template v-else>
<v-stepper-header>
<template v-for="n in steps">
<v-stepper-step
:key="`${n}-step`"
:complete="e1 > n"
:step="n"
:editable="editable"
>
Step {{ n }}
</v-stepper-step>
<v-divider
v-if="n !== steps"
:key="n"
></v-divider>
</template>
</v-stepper-header>
<v-stepper-items>
<v-stepper-content
v-for="n in steps"
:key="`${n}-content`"
:step="n"
>
<v-card
class="mb-12"
color="grey lighten-1"
height="200px"
></v-card>
<v-btn
color="primary"
@click="nextStep(n)"
>
Continue
</v-btn>
<v-btn text>Cancel</v-btn>
</v-stepper-content>
</v-stepper-items>
</template>
</v-stepper>
</div>
</template>
<script>
export default {
data () {
return {
e1: 1,
steps: 2,
vertical: false,
altLabels: false,
editable: true,
}
},
watch: {
steps (val) {
if (this.e1 > val) {
this.e1 = val
}
},
vertical () {
this.e1 = 2
requestAnimationFrame(() => this.e1 = 1) // Workarounds
},
},
methods: {
onInput (val) {
this.steps = parseInt(val)
},
nextStep (n) {
if (n === this.steps) {
this.e1 = 1
} else {
this.e1 = n + 1
}
},
},
}
</script>
示例
下面是一些简单到复杂的例子。
可编辑步骤
用户随时可以选择可编辑的步骤并将跳转到该步。
template
<template>
<v-stepper>
<v-stepper-header>
<v-stepper-step
complete
editable
step="1"
>
Select campaign settings
</v-stepper-step>
<v-divider></v-divider>
<v-stepper-step
complete
step="2"
>Create an ad group</v-stepper-step>
<v-divider></v-divider>
<v-stepper-step
step="3"
editable
>
Create an ad
</v-stepper-step>
</v-stepper-header>
</v-stepper>
</template>
不可编辑步骤
不可编辑步骤(Non-editable steps)强制用户在整个流程中进行线性处理。
template
<template>
<v-stepper value="2">
<v-stepper-header>
<v-stepper-step step="1" complete>Select campaign settings</v-stepper-step>
<v-divider></v-divider>
<v-stepper-step step="2">Create an ad group</v-stepper-step>
<v-divider></v-divider>
<v-stepper-step step="3">Create an ad</v-stepper-step>
</v-stepper-header>
</v-stepper>
</template>
可选步骤
可选步骤可由子文本调出。
template
<template>
<div>
<v-stepper value="1">
<v-stepper-header>
<v-stepper-step step="1">Select campaign settings</v-stepper-step>
<v-divider></v-divider>
<v-stepper-step step="2">
Create an ad group
<small>Optional</small>
</v-stepper-step>
<v-divider></v-divider>
<v-stepper-step step="3">Create an ad</v-stepper-step>
</v-stepper-header>
</v-stepper>
<v-stepper value="2" class="mt-12">
<v-stepper-header>
<v-stepper-step step="1" complete>Select campaign settings</v-stepper-step>
<v-divider></v-divider>
<v-stepper-step step="2">
Create an ad group
<small>Optional</small>
</v-stepper-step>
<v-divider></v-divider>
<v-stepper-step step="3">Create an ad</v-stepper-step>
</v-stepper-header>
</v-stepper>
</div>
</template>
水平步骤线
水平步骤线通过定义的步骤将用户沿 x轴 移动。
template
<template>
<v-stepper value="1">
<v-stepper-header>
<v-stepper-step step="1">Select campaign settings</v-stepper-step>
<v-divider></v-divider>
<v-stepper-step step="2">Create an ad group</v-stepper-step>
<v-divider></v-divider>
<v-stepper-step step="3">Create an ad</v-stepper-step>
</v-stepper-header>
</v-stepper>
</template>
垂直步骤线
水平步骤线通过定义的步骤将用户沿 y轴 移动。其他地方与水平方向的一致。
template script
<template>
<v-stepper v-model="e6" vertical>
<v-stepper-step :complete="e6 > 1" step="1">
Select an app
<small>Summarize if needed</small>
</v-stepper-step>
<v-stepper-content step="1">
<v-card color="grey lighten-1" class="mb-12" height="200px"></v-card>
<v-btn color="primary" @click="e6 = 2">Continue</v-btn>
<v-btn text>Cancel</v-btn>
</v-stepper-content>
<v-stepper-step :complete="e6 > 2" step="2">Configure analytics for this app</v-stepper-step>
<v-stepper-content step="2">
<v-card color="grey lighten-1" class="mb-12" height="200px"></v-card>
<v-btn color="primary" @click="e6 = 3">Continue</v-btn>
<v-btn text>Cancel</v-btn>
</v-stepper-content>
<v-stepper-step :complete="e6 > 3" step="3">Select an ad format and name ad unit</v-stepper-step>
<v-stepper-content step="3">
<v-card color="grey lighten-1" class="mb-12" height="200px"></v-card>
<v-btn color="primary" @click="e6 = 4">Continue</v-btn>
<v-btn text>Cancel</v-btn>
</v-stepper-content>
<v-stepper-step step="4">View setup instructions</v-stepper-step>
<v-stepper-content step="4">
<v-card color="grey lighten-1" class="mb-12" height="200px"></v-card>
<v-btn color="primary" @click="e6 = 1">Continue</v-btn>
<v-btn text>Cancel</v-btn>
</v-stepper-content>
</v-stepper>
</template>
<script>
export default {
data () {
return {
e6: 1,
}
},
}
</script>
线性步骤
线性步骤始终沿着你定义的路径移动。
template
<template>
<div>
<v-stepper>
<v-stepper-header>
<v-stepper-step step="1">Select campaign settings</v-stepper-step>
<v-divider></v-divider>
<v-stepper-step step="2">Create an ad group</v-stepper-step>
<v-divider></v-divider>
<v-stepper-step step="3">Create an ad</v-stepper-step>
</v-stepper-header>
</v-stepper>
<v-stepper value="2" class="mt-12">
<v-stepper-header>
<v-stepper-step step="1" complete>Select campaign settings</v-stepper-step>
<v-divider></v-divider>
<v-stepper-step step="2">Create an ad group</v-stepper-step>
<v-divider></v-divider>
<v-stepper-step step="3">Create an ad</v-stepper-step>
</v-stepper-header>
</v-stepper>
<v-stepper value="3" class="mt-12">
<v-stepper-header>
<v-stepper-step step="1" complete>Select campaign settings</v-stepper-step>
<v-divider></v-divider>
<v-stepper-step step="2" complete>Create an ad group</v-stepper-step>
<v-divider></v-divider>
<v-stepper-step step="3">Create an ad</v-stepper-step>
</v-stepper-header>
</v-stepper>
</div>
</template>
Vuetify Reddit
Connect with developers across the globe on the Vuetify subreddit.
ads by Vuetify
](https://www.reddit.com/r/vuetifyjs/?ref=vuetifyjs.com)
非线性步骤
非线性步骤可以让用户按照自己选择路线在流程中移动。
template
<template>
<div>
<v-stepper non-linear>
<v-stepper-header>
<v-stepper-step
editable
step="1"
>
Select campaign settings
</v-stepper-step>
<v-divider></v-divider>
<v-stepper-step
editable
step="2"
>
Create an ad group
</v-stepper-step>
<v-divider></v-divider>
<v-stepper-step
step="3"
editable
>
Create an ad
</v-stepper-step>
</v-stepper-header>
</v-stepper>
<v-stepper
class="mt-12"
non-linear
>
<v-stepper-header>
<v-stepper-step
complete
editable
step="1"
>
Select campaign settings
</v-stepper-step>
<v-divider></v-divider>
<v-stepper-step
editable
step="2"
>
Create an ad group
</v-stepper-step>
<v-divider></v-divider>
<v-stepper-step
complete
editable
step="3"
>
Create an ad
</v-stepper-step>
</v-stepper-header>
</v-stepper>
<v-stepper
class="mt-12"
non-linear
value="3"
>
<v-stepper-header>
<v-stepper-step
complete
editable
step="1"
>
Select campaign settings
</v-stepper-step>
<v-divider></v-divider>
<v-stepper-step
complete
editable
step="2"
>
Create an ad group
</v-stepper-step>
<v-divider></v-divider>
<v-stepper-step
complete
editable
step="3"
>
Create an ad
</v-stepper-step>
</v-stepper-header>
</v-stepper>
</div>
</template>
备用标签
步骤组件也有一个放置在步骤下方的备用标签样式。
template
<template>
<div>
<v-stepper alt-labels>
<v-stepper-header>
<v-stepper-step step="1">Ad unit details</v-stepper-step>
<v-divider></v-divider>
<v-stepper-step step="2">Ad sizes</v-stepper-step>
<v-divider></v-divider>
<v-stepper-step step="3">Ad templates</v-stepper-step>
</v-stepper-header>
</v-stepper>
<v-stepper alt-labels class="mt-12">
<v-stepper-header>
<v-stepper-step step="1">Ad unit details</v-stepper-step>
<v-divider></v-divider>
<v-stepper-step step="2">
Ad sizes
<small>Optional</small>
</v-stepper-step>
<v-divider></v-divider>
<v-stepper-step step="3">Ad templates</v-stepper-step>
</v-stepper-header>
</v-stepper>
</div>
</template>
多行表示的错误状态
可以显示错误状态来通知用户必须采取的一些行动。
template
<template>
<v-stepper>
<v-stepper-header>
<v-stepper-step step="1">Ad unit details</v-stepper-step>
<v-divider></v-divider>
<v-stepper-step :rules="[() => false]" step="2">
Ad templates
<small>Alert message</small>
</v-stepper-step>
<v-divider></v-divider>
<v-stepper-step step="3">Ad sizes</v-stepper-step>
</v-stepper-header>
</v-stepper>
</template>
备用标签样式的多行错误状态显示
错误状态的显示同样可以应用于备用标签样式。
template
<template>
<v-stepper alt-labels>
<v-stepper-header>
<v-stepper-step step="3" complete>Ad type</v-stepper-step>
<v-divider></v-divider>
<v-stepper-step step="4" complete>Ad style</v-stepper-step>
<v-divider></v-divider>
<v-stepper-step :rules="[() => false]" step="5">
Custom channels
<small>Alert message</small>
</v-stepper-step>
<v-divider></v-divider>
<v-stepper-step step="6">Get code</v-stepper-step>
</v-stepper-header>
</v-stepper>
</template>
垂直的多行错误状态显示
同样的,错误状态也可以应用于垂直的步骤。
template script
<template>
<v-stepper v-model="e13" vertical>
<v-stepper-step step="1" complete>
Name of step 1
</v-stepper-step>
<v-stepper-content step="1">
<v-card color="grey lighten-1" class="mb-12" height="200px"></v-card>
<v-btn color="primary" @click="e13 = 2">Continue</v-btn>
<v-btn text>Cancel</v-btn>
</v-stepper-content>
<v-stepper-step step="2" complete>Name of step 2</v-stepper-step>
<v-stepper-content step="2">
<v-card color="grey lighten-1" class="mb-12" height="200px"></v-card>
<v-btn color="primary" @click="e13 = 3">Continue</v-btn>
<v-btn text>Cancel</v-btn>
</v-stepper-content>
<v-stepper-step :rules="[() => false]" step="3">
Ad templates
<small>Alert message</small>
</v-stepper-step>
<v-stepper-content step="3">
<v-card color="grey lighten-1" class="mb-12" height="200px"></v-card>
<v-btn color="primary" @click="e13 = 4">Continue</v-btn>
<v-btn text>Cancel</v-btn>
</v-stepper-content>
<v-stepper-step step="4">View setup instructions</v-stepper-step>
<v-stepper-content step="4">
<v-card color="grey lighten-1" class="mb-12" height="200px"></v-card>
<v-btn color="primary" @click="e13 = 1">Continue</v-btn>
<v-btn text>Cancel</v-btn>
</v-stepper-content>
</v-stepper>
</template>
<script>
export default {
data () {
return {
e13: 2,
}
},
}
</script>
动态步骤
步骤可以动态的添加和移除,如果删除的是当前处于激活状态的步骤,请务必通过更改应用模型来解决这个问题。
template script
<template>
<div>
<v-card class="mb-4">
<v-card-text>
<v-select
v-model="steps"
:items="[2, 3, 4, 5, 6]"
label="# of steps"
></v-select>
</v-card-text>
</v-card>
<v-stepper v-model="e1">
<v-stepper-header>
<template v-for="n in steps">
<v-stepper-step
:key="`${n}-step`"
:complete="e1 > n"
:step="n"
editable
>
Step {{ n }}
</v-stepper-step>
<v-divider
v-if="n !== steps"
:key="n"
></v-divider>
</template>
</v-stepper-header>
<v-stepper-items>
<v-stepper-content
v-for="n in steps"
:key="`${n}-content`"
:step="n"
>
<v-card
class="mb-12"
color="grey lighten-1"
height="200px"
></v-card>
<v-btn
color="primary"
@click="nextStep(n)"
>
Continue
</v-btn>
<v-btn text>Cancel</v-btn>
</v-stepper-content>
</v-stepper-items>
</v-stepper>
</div>
</template>
<script>
export default {
data () {
return {
e1: 1,
steps: 2,
}
},
watch: {
steps (val) {
if (this.e1 > val) {
this.e1 = val
}
},
},
methods: {
nextStep (n) {
if (n === this.steps) {
this.e1 = 1
} else {
this.e1 = n + 1
}
},
},
}
</script>