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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<template>
<van-panel :title="title">
<ul>
<li
v-for="value in menus"
:key="value.id"
:id="value.id"
@click="menuClick(value.name)"
>
<div style="display:flex;">
<div class="divnew1">
<van-image v-bind:src="value.img" style="height: 80px;" />
</div>
<div>
<div style="margin-left: 10px;">
<span>{{value.text}}</span>
</div>
<div class="divnew2">
<span class="colorname">¥{{value.price}}</span>
</div>
</div>
</div>
</li>
</ul>
</van-panel>
</template>
<script lang="ts">
import {
Vue,
Component,
Prop,
Provide,
Emit,
Watch
} from "vue-property-decorator";
@Component({
components: {}
})
export default class AppPicrightMenu extends Vue {
/**
* 名称
*
* @type {string}
* @memberof AppPicrightMenu
*/
@Prop() public title?: string;
/**
* 菜单数据
*
* @type {Array<any>}
* @memberof AppPicrightMenu
*/
@Prop() public menus?: Array<any>;
/**
*存储后的菜单
*@memberof AppPicrightMenu
*/
public groupMenus: Array<any> = [];
/**
* 监听菜单数据
* @memberof AppPicrightMenu
*/
@Watch("menus", { immediate: true, deep: true })
onMenusChanged(val: any, oldVal: any) {
if (val) {
if (val.length >= 8) {
let tempArray:Array<any> = [];
val.forEach((item: any, index: any) => {
if (index % 8 == 0) {
if (index != 0) {
this.groupMenus.push(tempArray);
}
tempArray = [];
}
tempArray.push(item);
});
if (tempArray.length > 0) {
this.groupMenus.push(tempArray);
}
} else {
this.groupMenus = val;
}
}
}
/**
* 菜单点击事件
*
* @memberof AppPicrightMenu
*/
public menuClick($event: any) {
this.$emit("menuClick", $event);
}
}
</script>
<style lang="less">
@import "./app-picright-menu.less";
</style>