窗口

v-window 组件提供将内容从一个窗口转换到另一个窗口的基础功能。其他组件,如 v-tabs, v-carouselv-stepper 在它们的核心中利用了这个组件。

用例

v-window 被设计成可以轻松地循环浏览内容,它提供了一个简单的接口来创建真正的自定义实现。

template script


  1. <template>
  2. <v-row align="center">
  3. <v-item-group
  4. v-model="window"
  5. class="shrink mr-6"
  6. mandatory
  7. tag="v-flex"
  8. >
  9. <v-item
  10. v-for="n in length"
  11. :key="n"
  12. v-slot:default="{ active, toggle }"
  13. >
  14. <div>
  15. <v-btn
  16. :input-value="active"
  17. icon
  18. @click="toggle"
  19. >
  20. <v-icon>mdi-record</v-icon>
  21. </v-btn>
  22. </div>
  23. </v-item>
  24. </v-item-group>
  25. <v-col>
  26. <v-window
  27. v-model="window"
  28. class="elevation-1"
  29. vertical
  30. >
  31. <v-window-item
  32. v-for="n in length"
  33. :key="n"
  34. >
  35. <v-card flat>
  36. <v-card-text>
  37. <v-row class="mb-4" align="center">
  38. <v-avatar color="grey" class="mr-4"></v-avatar>
  39. <strong class="title">Title {{ n }}</strong>
  40. <v-spacer></v-spacer>
  41. <v-btn icon>
  42. <v-icon>mdi-account</v-icon>
  43. </v-btn>
  44. </v-row>
  45. <p>
  46. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
  47. </p>
  48. <p>
  49. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
  50. </p>
  51. <p>
  52. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
  53. </p>
  54. </v-card-text>
  55. </v-card>
  56. </v-window-item>
  57. </v-window>
  58. </v-col>
  59. </v-row>
  60. </template>
  1. <script>
  2. export default {
  3. data: () => ({
  4. length: 3,
  5. window: 0,
  6. }),
  7. }
  8. </script>

Windows(窗口) - 图1

API

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

Windows(窗口) - 图2

实战场

template script


  1. <template>
  2. <v-row align="center">
  3. <v-row justify="space-around">
  4. <v-switch v-model="autorun" class="ma-2" label="Automatic switching"></v-switch>
  5. <v-switch v-model="showArrows" class="ma-2" label="Show arrows"></v-switch>
  6. <v-switch v-model="vertical" class="ma-2" label="Vertical"></v-switch>
  7. <v-switch v-model="reverse" class="ma-2" label="Reverse"></v-switch>
  8. </v-row>
  9. <v-window
  10. v-model="window"
  11. class="elevation-1"
  12. :vertical="vertical"
  13. :show-arrows="showArrows"
  14. :reverse="reverse"
  15. >
  16. <v-window-item
  17. v-for="n in length"
  18. :key="n"
  19. >
  20. <v-card flat>
  21. <v-card-text>
  22. <v-row class="mb-4" align="center">
  23. <v-avatar color="grey" class="mr-4"></v-avatar>
  24. <strong class="title">Title {{ n }}</strong>
  25. <v-spacer></v-spacer>
  26. <v-btn icon>
  27. <v-icon>mdi-account</v-icon>
  28. </v-btn>
  29. </v-row>
  30. <p>
  31. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
  32. </p>
  33. <p>
  34. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
  35. </p>
  36. <p>
  37. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
  38. </p>
  39. </v-card-text>
  40. </v-card>
  41. </v-window-item>
  42. </v-window>
  43. </v-row>
  44. </template>
  1. <script>
  2. export default {
  3. data: () => ({
  4. length: 3,
  5. window: 0,
  6. showArrows: false,
  7. vertical: false,
  8. reverse: false,
  9. autorun: false,
  10. }),
  11. created () {
  12. setInterval(() => {
  13. if (!this.autorun) return
  14. if (++this.window >= this.length) this.window = 0
  15. }, 1000)
  16. },
  17. }
  18. </script>

Windows(窗口) - 图3

示例

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

垂直

v-window 可以是垂直的。 垂直窗口具有 Y 轴过渡而不是 X 轴过渡。

template script


  1. <template>
  2. <v-card flat tile>
  3. <v-window v-model="onboarding" vertical>
  4. <v-window-item
  5. v-for="n in length"
  6. :key="`card-${n}`"
  7. >
  8. <v-card
  9. color="grey"
  10. height="200"
  11. >
  12. <v-row
  13. class="fill-height"
  14. align="center"
  15. justify="center"
  16. tag="v-card-text"
  17. >
  18. <h1 style="font-size: 5rem;" class="white--text">Slide {{ n }}</h1>
  19. </v-row>
  20. </v-card>
  21. </v-window-item>
  22. </v-window>
  23. <v-card-actions class="justify-space-between">
  24. <v-btn
  25. text
  26. @click="prev"
  27. >
  28. <v-icon>mdi-chevron-left</v-icon>
  29. </v-btn>
  30. <v-item-group
  31. v-model="onboarding"
  32. class="text-center"
  33. mandatory
  34. >
  35. <v-item
  36. v-for="n in length"
  37. :key="`btn-${n}`"
  38. v-slot:default="{ active, toggle }"
  39. >
  40. <v-btn
  41. :input-value="active"
  42. icon
  43. @click="toggle"
  44. >
  45. <v-icon>mdi-record</v-icon>
  46. </v-btn>
  47. </v-item>
  48. </v-item-group>
  49. <v-btn
  50. text
  51. @click="next"
  52. >
  53. <v-icon>mdi-chevron-right</v-icon>
  54. </v-btn>
  55. </v-card-actions>
  56. </v-card>
  57. </template>
  1. <script>
  2. export default {
  3. data: () => ({
  4. length: 3,
  5. onboarding: 0,
  6. }),
  7. methods: {
  8. next () {
  9. this.onboarding = this.onboarding + 1 === this.length
  10. ? 0
  11. : this.onboarding + 1
  12. },
  13. prev () {
  14. this.onboarding = this.onboarding - 1 < 0
  15. ? this.length - 1
  16. : this.onboarding - 1
  17. },
  18. },
  19. }
  20. </script>

Windows(窗口) - 图4

反转

反转 v-window 总是显示反向转换。

template script


  1. <template>
  2. <v-card flat tile>
  3. <v-window v-model="onboarding" reverse>
  4. <v-window-item
  5. v-for="n in length"
  6. :key="`card-${n}`"
  7. >
  8. <v-card
  9. color="grey"
  10. height="200"
  11. >
  12. <v-row
  13. class="fill-height"
  14. align="center"
  15. justify="center"
  16. tag="v-card-text"
  17. >
  18. <h1 style="font-size: 5rem;" class="white--text">Slide {{ n }}</h1>
  19. </v-row>
  20. </v-card>
  21. </v-window-item>
  22. </v-window>
  23. <v-card-actions class="justify-space-between">
  24. <v-btn
  25. text
  26. @click="prev"
  27. >
  28. <v-icon>mdi-chevron-left</v-icon>
  29. </v-btn>
  30. <v-item-group
  31. v-model="onboarding"
  32. class="text-center"
  33. mandatory
  34. >
  35. <v-item
  36. v-for="n in length"
  37. :key="`btn-${n}`"
  38. v-slot:default="{ active, toggle }"
  39. >
  40. <v-btn
  41. :input-value="active"
  42. icon
  43. @click="toggle"
  44. >
  45. <v-icon>mdi-record</v-icon>
  46. </v-btn>
  47. </v-item>
  48. </v-item-group>
  49. <v-btn
  50. text
  51. @click="next"
  52. >
  53. <v-icon>mdi-chevron-right</v-icon>
  54. </v-btn>
  55. </v-card-actions>
  56. </v-card>
  57. </template>
  1. <script>
  2. export default {
  3. data: () => ({
  4. length: 3,
  5. onboarding: 0,
  6. }),
  7. methods: {
  8. next () {
  9. this.onboarding = this.onboarding + 1 === this.length
  10. ? 0
  11. : this.onboarding + 1
  12. },
  13. prev () {
  14. this.onboarding = this.onboarding - 1 < 0
  15. ? this.length - 1
  16. : this.onboarding - 1
  17. },
  18. },
  19. }
  20. </script>

Windows(窗口) - 图5

Material Kit

A complete set of Material Inspired themes built with Vuetify on top of Vue CLI.

ads by Vuetify

](https://store.vuetifyjs.com/product/material-kit-theme?ref=vuetifyjs.com)

入职

v-window 使它很容易创建自定义组件,如不同风格的幻灯片。

template script


  1. <template>
  2. <v-card
  3. color="black"
  4. dark
  5. flat
  6. tile
  7. >
  8. <v-window v-model="onboarding">
  9. <v-window-item
  10. v-for="n in length"
  11. :key="`card-${n}`"
  12. >
  13. <v-card
  14. color="transparent"
  15. height="200"
  16. >
  17. <v-row
  18. class="fill-height"
  19. align="center"
  20. justify="center"
  21. tag="v-card-text"
  22. >
  23. Transparent themed, for background-imaged slides. Background color black added for demonstration purposes.
  24. </v-row>
  25. </v-card>
  26. </v-window-item>
  27. </v-window>
  28. <v-card-actions class="justify-space-between">
  29. <v-btn
  30. text
  31. @click="prev"
  32. >
  33. <v-icon>mdi-chevron-left</v-icon>
  34. </v-btn>
  35. <v-item-group
  36. v-model="onboarding"
  37. class="text-center"
  38. mandatory
  39. >
  40. <v-item
  41. v-for="n in length"
  42. :key="`btn-${n}`"
  43. v-slot:default="{ active, toggle }"
  44. >
  45. <v-btn
  46. :input-value="active"
  47. icon
  48. @click="toggle"
  49. >
  50. <v-icon>mdi-record</v-icon>
  51. </v-btn>
  52. </v-item>
  53. </v-item-group>
  54. <v-btn
  55. text
  56. @click="next"
  57. >
  58. <v-icon>mdi-chevron-right</v-icon>
  59. </v-btn>
  60. </v-card-actions>
  61. </v-card>
  62. </template>
  1. <script>
  2. export default {
  3. data: () => ({
  4. length: 3,
  5. onboarding: 0,
  6. }),
  7. methods: {
  8. next () {
  9. this.onboarding = this.onboarding + 1 === this.length
  10. ? 0
  11. : this.onboarding + 1
  12. },
  13. prev () {
  14. this.onboarding = this.onboarding - 1 < 0
  15. ? this.length - 1
  16. : this.onboarding - 1
  17. },
  18. },
  19. }
  20. </script>

Windows(窗口) - 图6

帐户创建

使用平滑动画创建表单。v-window 会自动跟踪当前的选择索引以自动改变过渡方向。 这可以通过 reverse 属性手动控制。

template script


  1. <template>
  2. <v-card
  3. class="mx-auto"
  4. max-width="500"
  5. >
  6. <v-card-title class="title font-weight-regular justify-space-between">
  7. <span>{{ currentTitle }}</span>
  8. <v-avatar
  9. color="primary lighten-2"
  10. class="subheading white--text"
  11. size="24"
  12. v-text="step"
  13. ></v-avatar>
  14. </v-card-title>
  15. <v-window v-model="step">
  16. <v-window-item :value="1">
  17. <v-card-text>
  18. <v-text-field
  19. label="Email"
  20. value="john@vuetifyjs.com"
  21. ></v-text-field>
  22. <span class="caption grey--text text--darken-1">
  23. This is the email you will use to login to your Vuetify account
  24. </span>
  25. </v-card-text>
  26. </v-window-item>
  27. <v-window-item :value="2">
  28. <v-card-text>
  29. <v-text-field
  30. label="Password"
  31. type="password"
  32. ></v-text-field>
  33. <v-text-field
  34. label="Confirm Password"
  35. type="password"
  36. ></v-text-field>
  37. <span class="caption grey--text text--darken-1">
  38. Please enter a password for your account
  39. </span>
  40. </v-card-text>
  41. </v-window-item>
  42. <v-window-item :value="3">
  43. <div class="pa-4 text-center">
  44. <v-img
  45. class="mb-4"
  46. contain
  47. height="128"
  48. src="https://cdn.vuetifyjs.com/images/logos/v.svg"
  49. ></v-img>
  50. <h3 class="title font-weight-light mb-2">Welcome to Vuetify</h3>
  51. <span class="caption grey--text">Thanks for signing up!</span>
  52. </div>
  53. </v-window-item>
  54. </v-window>
  55. <v-divider></v-divider>
  56. <v-card-actions>
  57. <v-btn
  58. :disabled="step === 1"
  59. text
  60. @click="step--"
  61. >
  62. Back
  63. </v-btn>
  64. <v-spacer></v-spacer>
  65. <v-btn
  66. :disabled="step === 3"
  67. color="primary"
  68. depressed
  69. @click="step++"
  70. >
  71. Next
  72. </v-btn>
  73. </v-card-actions>
  74. </v-card>
  75. </template>
  1. <script>
  2. export default {
  3. data: () => ({
  4. step: 1,
  5. }),
  6. computed: {
  7. currentTitle () {
  8. switch (this.step) {
  9. case 1: return 'Sign-up'
  10. case 2: return 'Create a password'
  11. default: return 'Account created'
  12. }
  13. },
  14. },
  15. }
  16. </script>

Windows(窗口) - 图7