-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvue_7.html
72 lines (66 loc) · 2.09 KB
/
vue_7.html
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
<!DOCTYPE HTML>
<html>
<head>
<title>J1 Practice</title>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<style>
.formfield{margin-bottom:10px;}
</style>
</head>
<body>
<p>Dog Treats Problem. <a href="https://cemc.uwaterloo.ca/contests/computing/2020/index.html">from the J1 problem hosted by the CCC.</a></p>
<div id="app">
<div class="formfield">
<label>Small Treats: <label> <input v-model="treat_qty_small">
</div>
<div class="formfield">
<label>Medium Treats: <label> <input v-model="treat_qty_medium">
</div>
<div class="formfield">
<label>Large Treats: <label> <input v-model="treat_qty_large">
</div>
<div id="result">
<div><label>show diagnostics:</label><input type="checkbox" v-model="treat_diagnostics"></div>
<div v-if="treat_diagnostics">Treat Total: {{treat_total}}</div>
<div v-if="treat_diagnostics">Is_Happy: {{is_happy}}</div>
<span v-if="is_happy">{{dog_name}} is Happy!</span>
<span v-else>{{dog_name}} is sad..</span>
</div>
</div>
<script>
var app = new Vue({
el: '#app',
data:{
treat_diagnostics:false,
dog_name:"Barley",
treat_qty_small:0,
treat_qty_medium:0,
treat_qty_large:0,
treat_value_small:1,
treat_value_medium:2,
treat_value_large:3
},
computed:{
treat_total:function(){
return (this.treat_qty_small * this.treat_value_small) +
(this.treat_qty_medium * this.treat_value_medium) +
(this.treat_qty_large * this.treat_value_large);
},
is_happy:function(){
return this.treat_total>=10;
}
}
});
</script>
<!--
v-model will allow you to quickly bind form elements to the data property.
Make sure to set a default value!
The Computed property can be used like data, except for values that are calculated from data properties.
In this example 'treat_total' is computed from data properties, and 'is_happy' is computed from 'treat_total'.
ASYNCHRONOUS LEARNING EXERCISE : J1
- Find any J1 problem
- Imagine an interface that allows the user to enter data on the webpage
- Build using v-model and computed properties!
-->
</body>
</html>