|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
_4 k- l+ D: a/ F4 p4 A9 R$ K3 |' P) E: D# U6 Q4 [' u
* P+ Y4 T% B$ t* E7 `9 O, b" |
3 \$ B. G9 L K" q
<!DOCTYPE html>! j; g. F7 J- R% K7 B, S
<html lang="en">) t V) a/ O, g) F
<head>
' P( X" g4 h4 [- s f+ J" w <meta charset="UTF-8">
`" a8 |/ B! I$ A8 w$ B <title>to Do list</title>: D! X1 G- x/ q
<script src="./vue.js"></script>
- [3 u g5 O# t5 L</head># L: B8 @: {; P1 ^
<body>
5 N/ h: A2 l5 H! W+ t# { <div id="root">2 l* A. e# `6 b! n
<input type="text" v-model="inputVaule" />
$ ^6 Q: }6 A$ P. y5 Y$ m <button @click="Submit">Submit</button>
7 H, Z9 S) J* ~1 L- F <ul>
) |* u% _$ y. o( m J <todo-item v-for="(item,index) in List"
+ ~, i3 f2 L w1 A& U: i :key="index" 7 x% { x0 `* U
:content="item"
/ E8 t! j7 x# h9 U :index="index"
" j" C _2 f# z* a- F @delete="handleDelete"
* }: p. [: }9 Q; j8 A# x0 i" l >" l. N. V7 e& u7 Z. D7 {/ X
</todo-item>
% R7 S/ v. T. W; F) f8 ^2 W </ul>
+ T: r! j9 h2 s$ [ </div>% t8 k4 m% Y [" z
<script>
$ U; {& r3 E: p/ z Vue.component('todo-item', {
/ R+ ~, b- a. } props: ['content','index'],2 ?/ V( |0 z! l+ b1 C, h M7 G
template: '<li @click="deleteRow">{{content}}</li>',
2 _* ^: }( i% u" w methods: {
z M3 [" L4 v1 C deleteRow:function(){
# J% e' l8 X$ F9 y) ?* | this.$emit('delete',this.index);
4 d, `% u/ S" j& \# h }
$ M( G& \) `8 T# o/ x }4 l$ U+ H3 z7 r
})3 c' Z$ M- b8 S. `
new Vue({8 h5 a3 [) E7 L- r4 i) q- _7 `
el: '#root',
( x% f8 L0 W4 V* j/ z; M4 x* H data: {
, J8 X4 u: l) }3 ~3 U, }* [! Q inputVaule: '',
c0 a! C1 p# f' k& _ List: []. ]5 K3 z; L7 X# O- Q: ]
},
! X' c: O, m! [" h, a! e2 S+ J; ~ methods: {1 Q1 t; K. C- \# G& F& y/ [
Submit: function () {
6 @: v5 r- Q. h# Q if (this.inputVaule != '') {& X( F! y+ A7 V' m6 z; t2 e
this.List.push(this.inputVaule);
, a) p4 T5 S+ t* j9 \ }
9 Q3 P4 s# G% L& ~2 D0 F this.inputVaule = '';# k1 q1 w8 [7 Q' Z. I: L
},
/ u7 A# Z: ?) p$ | handleDelete: function(index) {
3 l- L/ B* Q" D( Q$ N: x this.List.splice(index,1);
3 a# i0 k5 B! b( B l( Z. c2 K8 @$ s }( N* H, C" k" K2 z' o
}! S2 V5 w4 x- b9 |3 u
}): X& B: t) l# Y( i7 t
</script>% \1 R! o2 ]& V) l, _
</body>6 W3 m( \' {) a8 d* ~& P: T
</html>
# _5 Q' ^( E# }; P: h
! y1 C- Y! b* v5 o/ n9 @7 S
) U/ {* E$ s# v5 M |
|