-
Notifications
You must be signed in to change notification settings - Fork 0
/
vue-nested-list.js
73 lines (69 loc) · 1.81 KB
/
vue-nested-list.js
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
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global.VueNestedList = factory());
}(this, (function () { 'use strict';
let NestedUl = {
name: 'nested-ul',
props: {
content: {
type: Array,
required: true
},
maxLength: {
type: Number,
default: 500
}
},
template: "<span v-if='content.length > maxLength'>[Array of length {{content.length}}: too many items to show]</span>"
+"<ul v-else>"
+"<li v-for='item in content'>"
+"<nested-list v-bind:content='item' v-bind:max-length='maxLength'></nested-list>"
+"</li>"
+"</ul>"
};
let NestedDl = {
name: 'nested-dl',
props: {
content: {
type: Object,
required: true
},
maxLength: {
type: Number,
default: 500
}
},
template:
"<span v-if='Object.keys(content).length > maxLength'>[Object with {{Object.keys(content).length}} keys: too many to show]</span>"
+"<dl v-else>"
+"<template v-for='(value, key) in content'>"
+"<dt>{{key}}</dt>"
+"<dd>"
+"<nested-list v-bind:content='value' v-bind:max-length='maxLength'></nested-list>"
+"</dd>"
+"</template>"
+"</dl>"
};
let NestedList = {
name: 'nested-list',
components: {
'nested-dl' : NestedDl,
'nested-ul' : NestedUl
},
props: {
content: {
required: true
},
maxLength: {
type: Number,
default: 500
}
},
template:
"<nested-ul v-if='Object.prototype.toString.call( content ) === \"[object Array]\"' v-bind:content='content' v-bind:max-length='maxLength'></nested-ul>"
+"<nested-dl v-else-if='typeof content === \"object\" && content !== null' v-bind:content='content' v-bind:max-length='maxLength'></nested-dl>"
+"<span v-else>{{content}}</span>"
};
return NestedList;
})));