|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
% u( }' ] |: z+ U5 W" K7 T8 r1 p2 Y' e5 O8 i- [
5 X5 Q6 l* f& V( T1 d8 t3 {! c4 r5 Y$ j$ O1 c" m N
<template>
4 R8 T# v% R, O3 B <div id="App">
- M9 Z' E" x: c% y <input v-model="inputValue" />
6 @6 z5 D0 u# b9 J$ [2 `0 q1 b3 Z* T <button @click="submit">Submit</button>
; m7 D4 X/ T. @' S5 h <ul>% Z* [* G; R0 _! W0 b, {: }- H
<todoItem4 M1 L$ H7 |5 P z. m+ o' M% Y
v-for="(item,index) in List": R \# S7 K* G( `0 d( X% O
:key="index"
' ~( Z6 r0 S1 s. _$ i4 R& _ :content="item"
0 r1 @$ }/ ]9 p: f3 `5 | :index="index"
9 e4 u ^$ Z/ u( B9 g. Y5 B' n7 k @delete="handleDelete"! s1 X7 b1 S8 N1 Y8 D0 x. m$ w0 e
></todoItem>
& ]% e0 R# R: ?. e3 g </ul>
8 U1 a/ h9 _$ i" \0 S </div>
' O' f. o6 a8 {# `1 F</template>' I) f5 t* l% k. {9 M+ `; X& A
/ Q9 W. I9 a, T: _" V: X<script>; u& r9 [& A6 B7 H
import todoItem from "@/components/item.vue";
) H8 _* y: l' I
1 i4 b5 |3 B% }5 P# jexport default {
0 Z& H' _5 c | L- D) D data: function() {/ B, g8 n& Z d4 M- x. Q! h
return {4 J/ `6 F/ r( h: j
List: [],2 h2 D, v2 L: o# k
inputValue: ""
& ?5 Q0 s3 T2 @/ i };; B+ i6 j& @6 ~- l' h+ g q
},
6 Q; Z0 z: ]5 B# z components: {
) n O; K+ J2 M7 C5 G n todoItem
! W$ T! o$ L& @0 C/ e, t0 x },% l2 e- y$ }: s& B9 ~ j
methods: {4 k: m$ @ H1 y. R V
submit: function() {) Q2 B c$ O( G/ H
if (this.inputValue != "") {
$ i7 r! ~( ?/ |/ T. y this.List.push(this.inputValue);
% e: {$ u( `$ S3 `% H' D3 b }, i9 t& D! E* [; T2 X# q r d- U
this.inputValue = "";
8 s4 K* C5 Q5 I" y4 p5 `* y8 a% N },/ `7 Z) z' ]& a0 S6 Y8 u1 @5 }, [
handleDelete: function(index) {; D: N0 H* M- E4 ~8 K+ J6 P
this.List.splice(index, 1);* ^2 e9 `" r9 Q2 t/ D9 e
}6 X f3 [' o( w% E, c( L
}6 v3 U) y6 P- L w1 j4 p
};
: f& w' o1 a3 b" k" s8 J</script>7 N( C8 i% z8 J2 F- C a
$ B( h7 @& D, Z' v: B( p0 |$ \0 e' E4 Q2 [7 E1 @
$ o# Z( U3 `4 p
4 s6 N# S, I1 |/ g9 {5 M9 Q4 I: G
# ~4 A, p) t8 \0 t# i4 z
( E+ L3 A& p3 |: W. F+ F+ b" ~& N( G/ D# X2 v2 n
<template>2 z& `9 E" C M( V. E1 Y
<li @click="deleteItem">{{content}}</li>* y# |8 \2 u. \6 g
</template>
/ d! e- r$ U; }; o5 S1 l# @& I
6 p/ x, x, B+ o9 Q<script>
7 l( r9 x+ P! @2 |, Vexport default {/ Z# c% ^4 x8 ?( m$ \1 s
props: ["content", "index"],6 H' z D. ?! x! t0 w7 d
data: function() {8 F0 f: K$ G o7 Z! S5 W4 A, C
return {};
# R9 d% \! i( u8 v9 O+ G6 C E },
' u; }' H* g* w8 r& c1 \ methods: {
8 `& u" H: A/ d& p deleteItem: function() {: \+ y) M4 m9 t7 W# i
this.$emit("delete", this.index);6 C3 E: p. Q R* `8 e( b; Z
}
3 v3 x. {% @2 G+ ` }
C j/ K" }9 b' p};
/ o7 r- h6 z6 q$ s) @</script>
, F; R' h7 X* Z5 a5 Z
, J' X( Q; M! U' f4 V
. q- G* D6 `8 Z1 \( M4 P( I4 O1 W7 c8 B8 _/ W; Z2 B, I
% A w7 ~; `3 P1 i9 b
|
|