-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
48 lines (46 loc) · 1.03 KB
/
index.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
function tabs() {
return {
current: 'Colors',
items: ['Colors', 'Quotes', 'About'],
changeTab(tab) {
this.current = tab;
}
};
}
function colors() {
return {
list: [
{ hex: '#2DCC72', name: 'green' },
{ hex: '#D64A4B', name: 'red' },
{ hex: '#8E46AC', name: 'purple' },
{ hex: '#3A87BB', name: 'blue' },
{ hex: '#BFC4C8', name: 'gray' }
],
selected: 'blue',
changeColor(name) {
this.selected = name;
},
getCurrentColor() {
return this.list.find(c => c.name === this.selected);
}
};
}
function quotes() {
return {
quote: {},
error: null,
loading: false,
async fetchQuote() {
const apiUrl = 'https://breaking-bad-quotes.herokuapp.com/v1/quotes';
this.loading = true;
try {
const result = await fetch(apiUrl);
const [quote] = await result.json();
this.quote = quote;
} catch (error) {
this.error = 'Oops. Something went wrong.';
}
this.loading = false;
}
};
}