-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path04.html
210 lines (209 loc) · 4.47 KB
/
04.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
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>task-04</title>
<script src="vue/vue.js"></script>
<script src="https://cdn.rawgit.com/chrisvfritz/5f0a639590d6e648933416f90ba7ae4e/raw/98739fb8ac6779cb2da11aaa9ab6032e52f3be00/currency-validator.js"></script>
<style>
</style>
</head>
<body>
<table id="app-01">
<tr is="my-component"></tr>
</table>
<div id="app-02">
<simple-counter></simple-counter>
<simple-counter></simple-counter>
<simple-counter></simple-counter>
</div>
<div id="app-03">
<input type="text" v-model='parentMsg'>
<child-11 v-bind:my-message="parentMsg"></child-11>
</div>
<div id="app-04">
<child prop-c="111"></child><br>
<child prop-c="333" prop-d="222" prop-f="11"></child>
</div>
<div id="app-05">
<p>{{total}}</p>
<button-counter v-on:user-defined="incrementTotal"></button-counter>
<button-counter v-on:user-defined="incrementTotal"></button-counter>
</div>
<div id="app-06">
<currency-input></currency-input>
<span>{{value}}</span>
<br>
<span>$<input v-bind:value="value" v-on:input="value=$event.target.value"></span>'
</div>
<div id="app-07">
<currency-input label="Price" v-model="price"></currency-input>
<currency-input label="Shipping" v-model="shipping"></currency-input>
<currency-input label="Handling" v-model="handling"></currency-input>
<currency-input label="Discount" v-model="discount"></currency-input>
<p>Total: ${{total}}</p>
</div>
<script>
var app01=new Vue({
el:'#app-01',
components:{
'my-component':{
template:'<div>A custom component!</div>'
}
}
})
var app02=new Vue({
el:'#app-02',
components:{
'simple-counter':{
template:'<button v-on:click="counter +=1">{{counter}}</button>',
data:function(){
return {counter:0}
}
}
}
})
var app03=new Vue({
el:'#app-03',
components:{
'child-11':{
template:'<span>{{myMessage}}</span>',
props:['myMessage']
}
},
data:{
parentMsg:''
}
})
var app04=new Vue({
el:'#app-04',
components:{
'child':{
template:'<span>{{propC}}-{{propD}}-{{propE}}-{{propF}}</span>',
props:{
propC:{
type:String,
required:true
},
propD:[String,Number],
propE:{
type:[String,Number],
default:100
},
propF:{
validator:function(value){
return value>10
}
}
}
}
}
})
var app05=new Vue({
el:'#app-05',
components:{
'button-counter':{
template:'<button v-on:click="increment">{{counter}}</button>',
data:function(){
return{
counter:0
}
},
methods:{
increment:function(){
this.counter+=1
this.$emit('user-defined')
}
}
}
},
data:{
total:0
},
methods:{
incrementTotal:function(){
this.total+=1
}
}
})
app06=new Vue({
el:'#app-06',
components:{
'currency-input':{
template:'<span>$<input ref="input" v-bind:value="value" v-on:input="updateValue($event.target.value)"></span>',
props:['value'],
methods:{
updateValue:function(value){
var formattedValue = value
.trim()
.slice(0,value.indexOf('.')==-1?(value.length):(value.indexOf('.')+3))
if(formattedValue!==value){
this.$refs.input.value = formattedValue
}
this.$emit('input',Number(formattedValue))
}
}
}
},
data:{
value:'1'
}
})
Vue.component('currency-input',{
template:'<div>\
<label v-if="label">{{label}}</label>\
$<input ref="input" v-bind:value="value" v-on:input="updateValue($event.target.value)"\
v-on:focus="selectAll" v-on:blur="formatValue"></div>',
props:{
value:{
type:Number,
default:0
},
label:{
type:String,
default:''
}
},
mounted:function(){
this.formatValue()
},
methods:{
updateValue:function(value){
var result=currencyValidator.parse(value,this.value)
if(result.warning){
this.$refs.input.value=result.value
}
this.$emit('input',result.value)
},
formatValue:function(){
this.$refs.input.value =currencyValidator.format(this.value)
},
selectAll:function(event){
setTimeout(function(){
event.target.select()
},0)
}
}
})
var app07=new Vue({
el:'#app-07',
data:{
price:0,
shipping:0,
handling:0,
discount:0
},
computed:{
total:function(){
return ((
this.price*100+
this.shipping*100+
this.handling*100-
this.discount*100
)/100).toFixed(2)
}
}
})
</script>
</body>
</html>