0%

vuetify2

头像时间轴和圆点时间轴

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<v-timeline>
<v-timeline-item v-for="n in 3" :key="n" large>
<template v-slot:icon>
<v-avatar>
<img src="http://i.pravatar.cc/64" />
</v-avatar>
</template>
<template v-slot:opposite>
<span>Tus eu perfecto</span>
</template>
<v-card class="elevation-2">
<v-card-title class="headline">Lorem ipsum</v-card-title>
<v-card-text>Lorem ipsum dolor sit amet.</v-card-text>
</v-card>
</v-timeline-item>
</v-timeline>

<v-card class="mx-auto" max-width="400">
<v-card-text class="py-0">
<v-timeline align-top dense>
<v-timeline-item color="pink" small>
<v-row class="pt-1">
<v-col cols="3">
<strong>5pm</strong>
</v-col>
<v-col>
<strong>New Icon</strong>
<div class="caption">Mobile App</div>
</v-col>
</v-row>
</v-timeline-item>
<v-timeline-item color="teal lighten-3" small>
<v-row class="pt-1">
<v-col cols="3">
<strong>3-4pm</strong>
</v-col>
<v-col>
<strong>Meeting</strong>
<div class="caption mb-2">Hangouts</div>
</v-col>
</v-row>
</v-timeline-item>
<v-timeline-item color="pink" small>
<v-row class="pt-1">
<v-col cols="3">
<strong>12pm</strong>
</v-col>
<v-col>
<strong>Lunch break</strong>
</v-col>
</v-row>
</v-timeline-item>
<v-timeline-item color="teal lighten-3" small>
<v-row class="pt-1">
<v-col cols="3">
<strong>9-11am</strong>
</v-col>
<v-col>
<strong>Go Home</strong>
<div class="caption">Web App</div>
</v-col>
</v-row>
</v-timeline-item>
</v-timeline>
</v-card-text>
</v-card>

说明:将头像放入 icon 插槽,opposite 插槽将文本放入卡片对面。align-top 将圆点和 item 对齐到顶部,item 中 color 指圆点颜色。

工具提示

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<div class="text-center">
<v-tooltip left>
<template v-slot:activator="{ on, attrs }">
<v-btn color="primary" dark v-bind="attrs" v-on="on">Left</v-btn>
</template>
<span>Left tooltip</span>
</v-tooltip>
</div>
<template>
<v-container fluid class="text-center">
<v-row class="flex" justify="space-between">
<v-col cols="12">
<v-btn @click="show = !show">toggle</v-btn>
</v-col>

<v-col cols="12" class="mt-12">
<v-tooltip v-model="show" top>
<template v-slot:activator="{ on, attrs }">
<v-btn icon v-bind="attrs" v-on="on">
<v-icon color="grey lighten-1">mdi-cart</v-icon>
</v-btn>
</template>
<span>Programmatic tooltip</span>
</v-tooltip>
</v-col>
</v-row>
</v-container>
</template>

说明:插槽 activator 放置激活组件,需要将事件侦听器传递给指令,将对象传递给指令:on、v-on、attrs、v-bind,对齐属性有 left、top、bottom、right。还可以用 v-model 来控制工具提示的显示。

选项卡

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<template>
<v-card>
<v-toolbar color="cyan" dark flat>
<v-app-bar-nav-icon></v-app-bar-nav-icon>
<v-toolbar-title>App</v-toolbar-title>
<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>
<template v-slot:extension>
<v-tabs v-model="tab" centered slider-color="yellow" align-with-title>
<v-tab v-for="i in 3" :key="i" :href="`#tab-${i}`">Item {{ i }}</v-tab>
</v-tabs>
</template>
</v-toolbar>

<v-tabs-items v-model="tab">
<v-tab-item v-for="i in 3" :key="i" :value="`tab-${i}`">
<v-card flat>
<v-card-text v-text="'hello world'"></v-card-text>
</v-card>
</v-tab-item>
</v-tabs-items>
</v-card>
</template>
<script>
export default {
name: "HelloWorld",
data() {
return {
tab: null,
};
},
};
</script>

说明:v-app-bar-nav-icon 工具栏左边图标,v-spacer 将组件分为左右两部分,extension 槽位直接位于工具栏的主要内容下。可以使用 extension-height 属性显式设置高度。如果该插槽没有内容,可以使用 extended 属性代替。align-with-title将标题与工具栏标题对齐,slider-color 标签下面线的颜色。

搜索选项卡

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<template>
<v-card>
<v-toolbar color="purple" dark flat prominent>
<v-text-field
append-icon="mic"
class="mx-4"
flat
hide-details
label="Search"
prepend-inner-icon="search"
solo-inverted
></v-text-field>

<template v-slot:extension>
<v-tabs v-model="tabs" centered>
<v-tab v-for="n in 3" :key="n">Item {{ n }}</v-tab>
</v-tabs>
</template>
</v-toolbar>

<v-tabs-items v-model="tabs">
<v-tab-item>
<v-card flat>
<v-card-text>Lorem ipsum dolor sit amet.</v-card-text>
</v-card>
</v-tab-item>
<v-tab-item>
<v-card flat>
<v-card-title class="headline">Title</v-card-title>
<v-card-text>
<p>Duis lobortis massa imperdiet quam.</p>
</v-card-text>
</v-card>
</v-tab-item>
<v-tab-item>
<v-card flat>
<v-card-title class="headline">Title</v-card-title>
<v-card-text>
<p>Maecenas ullamcorpe.</p>
</v-card-text>
</v-card>
</v-tab-item>
</v-tabs-items>
</v-card>
</template>
<script>
export default {
name: "HelloWorld",
data: () => ({
tabs: null,
text: "Lorem ipsum dolor sit amet.",
}),
};
</script>

说明:text 背景透明,v-divider 分割线,其中的 vertical 垂直显示分割线。 prominent 将工具栏内容的高度增加到 128px。 append-icon 右侧附加图标,label 文本框中预先写入的标签,prepend-inner-icon 输入框左边添加图标。

自定义选项卡

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<template>
<v-card>
<v-tabs
v-model="tab"
background-color="primary"
show-arrows
dark
next-icon="mdi-arrow-right-bold-box-outline"
prev-icon="mdi-arrow-left-bold-box-outline"
>
<v-tab v-for="item in items" :key="item.tab">{{ item.tab }}</v-tab>
<v-tabs-items v-model="tab">
<v-tab-item v-for="item in items" :key="item.tab">
<v-card flat>
<v-card-text>{{ item.content }}</v-card-text>
</v-card>
</v-tab-item>
</v-tabs-items>
</v-tabs>


</v-card>
</template>
<script>
export default {
name: "HelloWorld",
data() {
return {
tab: null,
items: [
{ tab: "One", content: "Tab 1 Content" },
{ tab: "Two", content: "Tab 2 Content" },
{ tab: "Three", content: "Tab 3 Content" },
{ tab: "Four", content: "Tab 4 Content" },
{ tab: "Five", content: "Tab 5 Content" },
],
};
},
};
</script>

说明:show-arrows 如果选项卡项目超出其容器,则显示分页箭头。 对于移动设备,仅在使用此属性时才会显示箭头。v-tabs-item 选项卡内容,next-icon 左分页图标,prev-icon 右分页图标。

选项卡图标

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<template>
<v-card>
<v-tabs v-model="tab" background-color="deep-purple accent-4" centered dark icons-and-text>
<v-tabs-slider ></v-tabs-slider>

<v-tab href="#tab-1">
Recents
<v-icon>mdi-phone</v-icon>
</v-tab>

<v-tab href="#tab-2">
Favorites
<v-icon>mdi-heart</v-icon>
</v-tab>

<v-tab href="#tab-3">
Map
<v-icon>mdi-account-box</v-icon>
</v-tab>
</v-tabs>

<v-tabs-items v-model="tab">
<v-tab-item v-for="i in 3" :key="i" :value="`tab-${i}`">
<v-card flat>
<v-card-text>hello world</v-card-text>
</v-card>
</v-tab-item>
</v-tabs-items>
</v-card>
</template>
<script>
export default {
name: "HelloWorld",
data() {
return {
tab: null,
};
},
};
</script>

说明:v-tabs-slider 标签下的划线,icons-and-text 将图标放在文本上。

右对齐

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<template>
<v-card>
<v-tabs background-color="white" color="deep-purple accent-4" right>
<v-tab>Foo</v-tab>
<v-tab>Bar</v-tab>
<v-tab>Baz</v-tab>

<v-tab-item v-for="n in 3" :key="n">
<v-container fluid>
<v-row>
<v-col v-for="i in 6" :key="i" cols="12" md="4">
<v-img
:src="`https://picsum.photos/500/300?image=${i}`"
:lazy-src="`https://picsum.photos/10/6?image=${i}`"
aspect-ratio="1"
></v-img>
</v-col>
</v-row>
</v-container>
</v-tab-item>
</v-tabs>
</v-card>
</template>
<script>
export default {
name: "HelloWorld",
data() {
return {
tab: null,
};
},
};
</script>

说明:lazy-src 在等待主映像加载时显示的内容,通常是一个小型的base64编码的缩略图。有一个轻微的模糊滤镜应用。使用 vuetify-loader 来自动生成,aspect-ratio 计算为width/height,因此对于 1920x1080px 的图片,其值为 1.7778。 如果省略,将自动计算。

选项卡与工具栏

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<template>
<v-card>
<v-toolbar color="cyan" dark flat>
<v-app-bar-nav-icon></v-app-bar-nav-icon>
<v-toolbar-title>App</v-toolbar-title>
<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>
<template v-slot:extension>
<v-tabs v-model="tab" centered slider-color="yellow">
<v-tab v-for="i in 3" :key="i" :href="`#tab-${i}`">Item {{ i }}</v-tab>
</v-tabs>
</template>
</v-toolbar>

<v-tabs-items v-model="tab">
<v-tab-item v-for="i in 3" :key="i" :value="`tab-${i}`">
<v-card flat>
<v-card-text v-text="'hello world'"></v-card-text>
</v-card>
</v-tab-item>
</v-tabs-items>
</v-card>
</template>

图标选项卡

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<template>
<v-card>
<v-toolbar flat>
<v-app-bar-nav-icon></v-app-bar-nav-icon>
<v-toolbar-title>App</v-toolbar-title>
<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>
<template v-slot:extension>
<v-tabs v-model="tabs" fixed-tabs>
<v-tabs-slider></v-tabs-slider>
<v-tab href="#mobile-tabs-5-1" class="primary--text">
<v-icon>mdi-phone</v-icon>
</v-tab>
<v-tab href="#mobile-tabs-5-2" class="primary--text">
<v-icon>mdi-heart</v-icon>
</v-tab>
<v-tab href="#mobile-tabs-5-3" class="primary--text">
<v-icon>mdi-account-box</v-icon>
</v-tab>
</v-tabs>
</template>
</v-toolbar>

<v-tabs-items v-model="tabs">
<v-tab-item v-for="i in 3" :key="i" :value="`mobile-tabs-5-${i}`">
<v-card flat>
<v-card-text v-text="text"></v-card-text>
</v-card>
</v-tab-item>
</v-tabs-items>
</v-card>
</template>

说明:不带文字,适合桌面显示。fixed-tabs v-tabs-item min-width 160px, max-width 360px。

带菜单的选项卡

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<template>
<v-card>
<v-toolbar color="deep-purple accent-4" dark flat>
<v-app-bar-nav-icon></v-app-bar-nav-icon>
<v-toolbar-title>App</v-toolbar-title>
<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>

<template v-slot:extension>
<v-tabs v-model="currentItem" fixed-tabs slider-color="white">
<v-tab v-for="item in items" :key="item" :href="`#tab-${item}`">{{ item }}</v-tab>

<v-menu v-if="more.length" bottom left>
<template v-slot:activator="{ on, attrs }">
<v-btn text class="align-self-center mr-4" v-bind="attrs" v-on="on">
more
<v-icon right>mdi-menu-down</v-icon>
</v-btn>
</template>

<v-list class="grey lighten-3">
<v-list-item v-for="item in more" :key="item" @click="addItem(item)">{{ item }}</v-list-item>
</v-list>
</v-menu>
</v-tabs>
</template>
</v-toolbar>

<v-tabs-items v-model="currentItem">
<v-tab-item v-for="item in items.concat(more)" :key="item" :value="`tab-${item}`">
<v-card flat>
<v-card-text>
<h2>{{ item }}</h2>
{{ text }}
</v-card-text>
</v-card>
</v-tab-item>
</v-tabs-items>
</v-card>
</template>
<script>
export default {
name: "HelloWorld",
data: () => ({
currentItem: "tab-Web",
items: ["Web", "Offers", "Videos", "Hames"],
more: ["News", "Maps", "Books", "Flights", "Play"],
text:
"Lorem ipsum dolor sit amet.",
}),

methods: {
addItem(item) {
const removed = this.items.splice(0, 1);
this.items.push(...this.more.splice(this.more.indexOf(item), 1));
this.more.push(...removed);
this.$nextTick(() => {
this.currentItem = `tab-${item}`;
});
},
},
};
</script>

说明:v-menu 附加选项卡按钮,菜单是与组件一起创建的,方法是将其传递到 with 属性中,并具有用于设置菜单按钮样式的属性。v-btn on v-on v-bindv-on让侦听器打开和关闭菜单。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<template>
<v-card>
<v-tabs v-model="tab" background-color="primary" dark fixed-tabs show-arrows>
<v-tab>
</v-tab>
</v-tabs>

<v-tabs-items v-model="tab">
<v-tab-item>
<v-card flat>
<v-card-text></v-card-text>
</v-card>
</v-tab-item>
</v-tabs-items>
</v-card>
</template>

说明:background-color具有背景色,fixed-tabs使其位置固定,dark使非活动选项卡的文本变为灰色,show-arrows 当选项卡溢出时显示箭头。v-tab具有选项卡标题并具有选项卡项,v-tab-items 选项卡内容,v-model让我们控制哪个选项卡以编程方式处于活动状态。

您的打赏将会成为我前进的动力!!