-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
106 lines (91 loc) · 2.02 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
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
104
105
106
// This is an object literal. It is fluffy.
const gruf = {
name: 'Gruf',
mood: 'mischevious',
fluffy: true,
age: 4,
}
// Not Vue, how to respond to an event like a button click
const notVueButtonElement = document.getElementById('notVueButton');
const whatToDoWhenAButtonIsClicked = () => {
document.body.style = "background-color: pink";
}
notVueButtonElement.addEventListener(
"click",
whatToDoWhenAButtonIsClicked
);
const appConfig = {
// "syntax sugar shorthand" for setup: function() {
setup() {
const foodName = Vue.ref("pretzels");
console.log('Moo.');
const goatCount = Vue.ref(5);
const foodCount = Vue.ref(10);
const clock = Vue.ref(0);
const clockTick = () => {
clock.value += 1;
}
setInterval(clockTick, 1000)
// computed value, auto-refreshes based on changes to the data
const howToComputeTheMood = () => {
const enoughFood = foodCount.value >= goatCount.value;
// ? test true : false
return enoughFood ? 'happy' : 'super mad';
}
const mood = Vue.computed(howToComputeTheMood)
const vipList = Vue.ref([
'Gruf',
'Fawn',
'Billy',
]);
const vipName = Vue.ref("");
const addVIP = () => {
vipList.value.push(vipName.value);
vipName.value='';
}
const goatObject = Vue.ref( {
name: "",
powerLevel: 0,
isGrumpy: false,
});
const goatList = Vue.ref([]);
const addGoatObject = () => {
// ... is the JavaScript spread operator, but we're not using it.
goatList.value.push(goatObject.value);
goatObject.value = {
name: "",
powerLevel: 0,
isGrumpy: false,
};
}
console.log('What is goatCount?', goatCount);
const addGoats = (change) => {
goatCount.value += change;
}
return {
goatCount,
addGoats,
foodName,
foodCount,
mood,
vipList,
vipName,
addVIP,
clock,
goatObject,
goatList,
addGoatObject,
}
}
}
const app = Vue.createApp(appConfig);
app.component("color-box",{
template:"#template-color-box",
props:{
color:{
type:String,
required:true,
}
}
})
app.mount('#root');