|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
' d" D" v8 b& s5 k2 F1 E
) W, E9 ^" x6 |& o3 Z. d. [" d9 n: E
]' ^8 K1 H2 R
<!DOCTYPE html>0 x; }) m( p8 l0 C) C! {0 r3 d7 f
<html lang="en">. \) F& _: z/ M6 O
<head>7 h0 N; u- Z/ s+ p! o' }: C5 [" N+ K
<meta charset="UTF-8">
a* U6 R1 }: z$ |6 n# H <title>to Do list</title>
# s1 V9 _3 U7 \; b& K <script src="./vue.js"></script>
' e D& _! E3 Z0 U5 P" l</head>
$ F# X0 m9 o2 t5 L2 m: Y/ @3 h<body>
4 \9 |& J3 k( U$ m; t. f$ k& {0 Y <div id="root">7 Q/ X: r: l9 ~) e. y) K3 A
<input type="text" v-model="inputVaule" />; K) ?. b0 X0 Z: K+ _) |
<button @click="Submit">Submit</button>
# K8 [4 f: _) h; c2 o' l/ c z <ul>
6 S9 l& d+ Q8 X: {% O' e <todo-item v-for="(item,index) in List"
) ~0 x" X- F6 v' l' \) u+ E! P :key="index" ( [- T& f' z5 X/ F! { r. a
:content="item" 7 f% l4 _& c, q* i3 @9 K, l' m' _
:index="index"
! I4 f$ _# y6 Y% z: h @delete="handleDelete"
! o+ b8 S% X! S3 U; T >
7 ^; K0 H1 y! C2 `# N1 x6 H. c </todo-item>+ ~" L5 G- L0 N3 O0 h# Y
</ul> y: s- s& G1 R# i
</div>
7 F" l) {! o3 j <script>
# ~( C# m2 i$ N! ^( S4 Z/ l Vue.component('todo-item', {0 D6 p/ i( F/ C$ y
props: ['content','index'],
% {6 g9 q( c s template: '<li @click="deleteRow">{{content}}</li>',7 E2 h% s) S# \% l! f: H
methods: {9 d1 a/ f: q) U
deleteRow:function(){9 `0 S) P, S `5 v2 x% O
this.$emit('delete',this.index);
1 W$ l' p. z* L/ D3 \ }: B1 y. y# |8 n" X2 j
}
- |* @" ]* S/ N( d })
% D8 U& J/ _3 V, U& H new Vue({
% A. {4 ^" P4 f6 w [" J+ E Q el: '#root',
( n9 c$ k9 z9 e. D% H data: {
. ]1 P8 Q6 c& Y. V9 E { inputVaule: '',% v( {1 i5 k" J+ Q
List: []
& H5 [# X' N/ A# L% w },6 c; W7 s1 S, s: M
methods: {
8 o# d9 K/ V# b( S+ K6 D% w1 }4 b Submit: function () {
4 Q5 l6 Y9 U3 ?( q1 ?& F2 g2 c if (this.inputVaule != '') {' |& k$ G- x- e% h& I( o2 _! F
this.List.push(this.inputVaule);
4 ?) J _3 v( {- R; d }; } p: H4 ~0 ^! @$ [/ B
this.inputVaule = '';
2 l0 B9 Z( r1 A* @) c, z },: P3 s1 \( X, b" Q1 U, Q: O- Z
handleDelete: function(index) {0 y* J1 x# h: W, \' `4 n0 x3 N R s
this.List.splice(index,1); 5 U% L& V; N! A* v3 \
}
?* |6 p9 F$ `/ @! ^2 |2 S }( u9 I1 ?; N' M: p. s) W
})
6 O* {& k/ r7 Y7 p% _9 P </script>, w$ q( J* r' E5 ]" o: K$ w0 F. s
</body>" x, |( L4 h/ |/ \" I1 B+ F
</html>
2 K- t8 j( w0 P7 B$ T# V) R+ n, t$ d/ z; p( E: F/ _) J$ ~
+ z) F- r! V1 w/ w |
|