-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvue.html
More file actions
375 lines (329 loc) · 12.8 KB
/
Copy pathvue.html
File metadata and controls
375 lines (329 loc) · 12.8 KB
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Vue 示例</title>
</head>
<body>
<div id="app">
<!-- <table>
<tbody is="my-component"></tbody>
</table> -->
<my-component message="来之父组件的数据"> </my-component>
<my-component warning-text="提示信息"> </my-component>
<input type="text" v-model="msg"/>
<my-component :message="msg" @input="handleInput"> </my-component>
<my-component :init-count="100"></my-component>
<!-- <Card style="width: 350px;">
<p slot="title"> 与 xxx 聊天中</p>
<a href="#" slot="extra">
<Icon type="android-close" size="18"></Icon>
</a>
<div style="height: 100px;">
</div>
<div>
<Row :gutter="16">
<i-col span="17">
<i-input v-model="value" placeholder="请输入...">
</i-input>
</i-col>
<i-col>
<i-button type="primary" icon="paper-airplane">
发送
</i-button>
</i-col>
</Row>
</div>
</Card> -->
<select name="" id="" v-model="selected">
<!-- <option :value="{ number: 123 }">123</option> -->
<option v-for="option in books" :value="option.name">{{option.author}}</option>
</select>
<p>{{ selected.number }}</p>
<input type="checkbox" name="" id="toggle-id" v-model="toggle" :true-value="value1" :false-value="value2">
<label for="toggle-id">复选框</label>
<p>{{ toggle }}</p>
<p>{{ value1 }}</p>
<p>{{ value2 }}</p>
<input type="radio" name="" id="" v-model="picked" :value="value">
<label for="">单选框</label>
<p>{{ picked }}</p>
<p>{{ value }}</p>
<input type="radio" id="radiolog" name="radiolog" :checked="picked"/>
<label for="radiolog">单选框</label>
<input type="checkbox" v-model="pickedValue" name="" value="html" id="html" />
<label for="html">HTML</label>
<input type="checkbox" v-model="pickedValue" name="" value="js" id="js" />
<label for="js">JavaScript</label>
<input type="checkbox" v-model="pickedValue" name="" value="css" id="css" />
<label for="css">CSS</label>
<p>{{ pickedValue }}</p>
<select name="" id="" v-model="selected" multiple>
<option value="html">HTML</option>
<option>JavaScript</option>
<option>Css</option>
</select>
<p>{{ selected }}</p>
<textarea @input="handleInput" name="" id="" cols="30" rows="10"></textarea>
<input type="text" v-model="message" placeholder="输入">
<p>输入的内容是{{ message }}</p>
<ul>
<li v-for="book in books">
{{ book.name }}
</li>
</ul>
<input type="text" v-model="username" placeholder="your name" />
<p>{{ username }}</p>
<p>{{ a / 2 }}</p>
<p> {{ a > 1 ? 'OK' : 'No'}}</p>
<p>当前时间: {{ date }}</p>
<p>格式化后 当前时间: {{ date | formatDate }}</p>
<span v-html="link"></span>
<span v-pre>{{data.books}}</span>
<span >{{ text.split(',').reverse().join(',') }}</span>
<span >{{ reversedText }}</span>
<!-- 注意,不使用计算属性时,在方法中定义要带() -->
<span >{{ reversedTextNumber() }}</span>
<hr/>
<span v-if="show">显示这段话</span>
<!-- <button v-on:dblclick="handleClose">点击隐藏上面一段话</button> -->
<button v-on:click="show = false">点击隐藏上面一段话</button>
<hr/>
<!-- <a v-bind:href="url">www.flycode.me</a>
<img v-bind:src="imgUrl" alt=""> -->
<a :href="url">www.flycode.me</a>
<!-- <img :src="imgUrl" alt=""> -->
<hr/>
<p>姓名: {{ fullName }}</p>
<div class='static' :class="{ 'active' : isActive, 'error' : isError } "></div>
<div :class="classes"></div>
<div :class="[activeCls, errorCls]"> </div>
<div :class="[isActive ? activeCls : '' , errorCls]"> </div>
<div :class="[{'active' : isActive }, errorCls]"> </div>
<div :style="{'color': color, 'fontSize': fontSize + 'px' }"> 文本 </div>
<div :style="styles"> 文本 </div>
<div id="app" v-clock>
<span v-once>{{ message }}</span>
</div>
<span v-if="status == 1">状态为1时 显示这段话</span>
<span v-else-if="status == 2">状态为2时 显示这段话</span>
<span v-else>其他情况 显示这段话</span>
<template v-if="type == 'name'">
<label for="" >your name</label>
<input type="text" placeholder="你的名字" key="name-input"/>
</template>
<template v-else>
<label for="" >your Email</label>
<input type="text" placeholder="你的邮箱" key="email-input"/>
</template>
<button @click="handleToggleClick">切换输入类型</button>
<div v-show="status === 2">display 显示这段文字</div>
<ul>
<li v-for="(value, key, index) in user">
{{ index }} - {{ key }} - {{ value }}
</li>
</ul>
<ul>
<template v-for="book in filterBooks">
<li>书名 {{ book.name }}</li>
<li>作者 {{ book.author }}</li>
</template>
</ul>
点击次数 :{{ counter }}
<button @click="counter++"> + 1 </button>
<button @click="handleAdd(10)"> + 10 </button>
</div>
<script src="https://unpkg.com/vue/dist/vue.min.js" ></script>
<script>
var Child = {
template : '<div> 局部组件 </div>'
};
var data = {
counter: 0
};
var app = new Vue({
// el: '#app',
el: document.getElementById('app'),
data:{
msg: '',
toggle: false,
value1: 'a',
value2: 'b',
picked: false,
value: 123,
// selected: ['Css', 'html'],
selected: '',
// picked: false,
pickedValue: ['js', 'html'],
message: '',
books : [
{ name:'中华上下五千年'},
{ name:'世界上下一万年'},
{ name:'十万个为什么'},
],
username : '',
a : 10,
date: new Date(),
link: '<a href="#"> 这是一个链接 </a>',
text: '123,456',
show: true,
url: 'http://www.flycode.me',
imgUrl: 'http://static.v5.javamall.com.cn/attachment/goods/201511240139201504_thumbnail.jpg',
firstName: 'Jack',
lastName: 'Green',
isActive: true,
isError: false,
// error: false,
// error: null,
error: {
type: 'fail'
},
activeCls: 'active',
errorCls: 'error',
color: 'red',
fontSize: 14,
styles: {
color: 'red',
fontSize: 14 + 'px',
},
message: 'hello world',
status: 2,
type : 'name',
user: {
name: 'Areason',
gender: '男',
age: 6
},
books: [
{name : 'Vue 实战', author: 'rocky'},
{name : 'D JavaScript 实战', author: 'rocky'},
{name : 'C JavaScript 实战1231', author: 'rocky'},
{name : 'B JavaScript 实战12', author: 'rocky'},
{name : 'A JavaScript 实战12', author: 'rocky'},
],
counter: 0,
},
component: {
'my-component': Child,
},
methods: {
handleClose: function () {
this.show = false;
},
reversedTextNumber: function () {
//这里的this指向的是当前的Vue实例
return this.text.split(',').reverse().join(',')
},
handleToggleClick: function() {
this.type = this.type === 'name' ? 'mail' : 'name';
},
handleAdd: function (counter) {
counter = counter || 1
this.counter += counter;
},
handleInput: function(e) {
return this.message = e.target.value;
}
},
computed: {
classes: function () {
return {
active: this.isActive && !this.error,
'text-fail': this.error && this.error.type === 'fail'
}
},
reversedText: function () {
//这里的this指向的是当前的Vue实例
return this.text.split(',').reverse().join(',')
},
fullName: {
// getter 用于读取
get: function () {
return this.firstName + ' ' + this.lastName;
},
// 写入时触发
set: function (newValue) {
var names = newValue.split(' ');
this.firstName = names[0];
this.lastName = names[names.length - 1];
}
},
filterBooks: function() {
return this.books.sort(function (a, b){
if (a.name < b.name)
return -1;
if (a.name > b.name)
return 1;
return 0;
});
},
},
created: function () {
// console.log(this.a); //2
},
// mounted: function () {
// console.log(this.$el) // <div id="app"></div>
// var _this = this;
// this.timer = setInterval(function () {
// _this.date = new Date();
// }, 1000)
// },
// beforeDestory: function () {
// if (this.timer) {
// clearInterval(this.timer);
// }
// },
});
app.books = app.books.filter(function (item){
return item.name.match(/JavaScript/);
});
Vue.component('my-component', {
// template: '<div>{{ msg }}</div>',
// data: function() {
// return {
// msg: '组件内容',
// }
// }
// template: '<button @click="counter++">{{ counter }}</button>',
// data: function() {
// return data;
// }
// template: '<button @click="counter++"> {{ counter }} </button>',
// data: function () {
// return {
// counter: 0
// };
// }
// props: ['message'],
// template: '<div>{{ message }}</div>'
// props: ['warningText'],
// template: '<div> {{ warningText }} </div>'
props: ['message'],
template: '<div>{{ message }}</div>'
// props: ['initCount'],
// // template: '<div> {{ count }} </div>',
// template: '<div :style="style"> 组件内容 </div>',
// data: function () {
// return {
// count: this.initCount,
// }
// },
// computed: {
// style: function () {
// return {
// width: this.initCount + 'px',
// }
// }
// }
});
// Vue.set(app.books, 2, {
// name: '<CSS 泄密>',
// author: ' Lea Verou'
// });
// this.$set(app.books, 3, {
// name: '<CSS 泄密>',
// author: ' Lea Verou'
// });
</script>
</body>
</html>