|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
, l7 o6 G$ C& j, n- I
1 J a- g, z* ]' ^# ~3 v
) z v8 S; X& H) U! I
1 o0 k( \- [9 C% L<template>
4 Y$ v) e1 p$ |; C3 x <div id="App">8 i; Q4 ?9 o; s/ o. N+ Z5 X" P
<input v-model="inputValue" />
( k: [6 H5 m. E9 A <button @click="submit">Submit</button>
4 |2 Y: l a" C8 i' e <ul>4 o K S( `8 ?$ c7 o
<todoItem
- L" F; @6 N7 B4 B' x; c v-for="(item,index) in List"
0 H! @! r( @4 B) } :key="index"
) l3 K8 f' Q0 w1 R :content="item"
% R: i: I! t% ?* E+ Q. q' k: F :index="index"
8 @6 D/ M( L3 @' [9 w @delete="handleDelete". Q; m0 j$ x6 Q" X9 C% T
></todoItem>! D! }) a; o* r m0 Z
</ul>: @9 }9 A3 x& d, F
</div>/ n4 O6 f8 h) Q1 l( Z
</template>
$ {3 {/ S/ G$ x' h7 a; C7 w
& O. m7 X ^& q, H, w<script>
5 K. c( J0 A0 T/ E4 i& \import todoItem from "@/components/item.vue";6 R0 L4 h$ w$ S
/ I8 z- G' | C3 q$ e/ s4 l: }1 e" kexport default {
, W& F% L( N( s3 p3 R/ c+ T data: function() {& a* i9 x2 |- B
return {
5 y0 g4 b+ N n0 k3 E8 f List: [],, y0 o, `. [. {0 O
inputValue: ""2 x) ~ h3 p* k/ K4 ~4 s& w
};% Y M! j8 f. O, w: S
},8 `+ g0 H/ p' R% t; J0 G( \! P1 H
components: {3 T# p: J r5 @( I
todoItem0 H* U9 F) X! k' e8 \; p
},+ U* M: l- w& S( h) A3 v2 X$ I
methods: {6 Q" w w! E# a! u3 b. c
submit: function() {1 D) c" C; {4 i, q. E
if (this.inputValue != "") {
7 P* i2 d/ i, `0 F2 L6 Y this.List.push(this.inputValue);
1 ?; t) r4 Z" d' ]+ H: h }
3 Y) D$ r+ h; d2 U. s this.inputValue = "";; r1 `3 z& g1 v. {$ U9 Y. |1 Y D5 E
},
( Z% f: f1 w/ p0 F& a5 I handleDelete: function(index) {; i1 @" u& X" p3 L
this.List.splice(index, 1);5 r3 W0 q* R: q! _" J+ E2 C. W
}, ]6 V% i/ E: f
}
/ h6 f1 T6 U# G4 _. f5 a};/ d( e: }4 }- i' v! z+ n5 g
</script>
+ _$ O& N0 c B7 ?0 S* @, I
8 _! u# Y! R; z+ S5 O) [
9 S5 W% N8 ?- Z
2 U q8 g U3 p x4 h' S. j7 Z* n5 w; h' r0 p [& _: j
' j& \" F H9 u
, \4 F$ ~3 M" N
1 b" u, C, b: |& w<template>
" ?7 B7 G" l. t6 K6 a0 T' q <li @click="deleteItem">{{content}}</li>
. D+ p% s! @& }</template>, W+ {% y& c6 `7 I! @; d
! E) U3 p5 t( U2 R" S: B<script>
5 B7 F# {9 Y2 T Z5 Y' _5 rexport default {
8 {2 e8 |5 t2 O- ]: K props: ["content", "index"],
* V, N" Y: ?3 E3 n5 C data: function() {
) C' Q/ S e% v! w return {};
7 M( X4 K; I2 A5 |& X },
+ [& h3 H' j! E methods: {
/ |: o+ u6 N& n deleteItem: function() {
7 g7 I) J# u; A3 }; b this.$emit("delete", this.index);8 y- \* ^' s- [$ }: |+ q9 r7 B2 A
}
6 a% K' @8 L* v: L }
7 z2 `8 l# |5 ~$ R( B; V};
+ A' c5 D* q0 x3 J3 \9 b9 Y</script>( p% f, {0 R" E8 ~, p5 s; M( W
& v8 M$ z. p4 l4 ~
' [1 M( S- t) \7 J, \7 d
5 Y( T6 r. r1 C2 q+ _; X4 }, ]
1 i. t2 P! d1 r' s* L6 q8 P/ C6 d |
|