-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
52 lines (41 loc) · 868 Bytes
/
script.js
File metadata and controls
52 lines (41 loc) · 868 Bytes
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
const { createApp } = Vue;
createApp({
data() {
return {
content: null,
table: null,
search: null
}
},
computed: {
list() {
var list = this.table.data;
if (this.search) {
list = _.map(list, function (item) {
var s = JSON.stringify(item).toLowerCase();
if (s.includes(this.search.toLowerCase())) {
return item;
}
}.bind(this));
}
return list;
}
},
methods: {
loadFile(event) {
// credits: https://www.digitalocean.com/community/tutorials/vuejs-file-reader-component
const file = event.target.files[0];
const reader = new FileReader();
reader.onload = e => {
this.content = e.target.result;
}
reader.readAsText(file);
},
csvToJson() {
// ref. https://www.papaparse.com/docs
this.table = Papa.parse(this.content, {
header: true
});
}
}
}).mount('#app');