|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
5 h# U; o5 {4 Y2 s
- |5 {- `4 F" H3 W& l! D' z1 D- G
4 O5 N" f6 U( e8 O% e. n7 f) b% n1 O w- w0 F) ^7 ^
<template>
/ R8 e9 q/ e7 r @/ g9 { <div id="App">
9 ]4 I9 U- T% ?3 {5 n0 N% t" s <input v-model="inputValue" />( m6 b1 D) Y) C) R2 n0 v; l
<button @click="submit">Submit</button>0 c4 f) p. ^4 l4 d
<ul>( h, ]. t4 f2 w. M; {
<todoItem
# G2 w2 o0 ~6 Y' v) l$ | v-for="(item,index) in List"
- t4 ~5 Z# a* z. y :key="index"5 \* ?- w0 H3 {
:content="item"
8 x1 j. Z, y! Y+ `7 @$ `6 H# D :index="index", J" E7 g" b6 m+ }7 `' c4 e
@delete="handleDelete"
5 V u2 Q6 M1 w6 u- j, h3 V ></todoItem>
, ^# _6 w4 e, b" x1 n4 `4 s# t </ul>
* n Q e$ e- q1 [: i B </div>
, h% {0 F" M0 W3 G6 p</template>
* G# V+ @" m" r' }' |. r
2 n0 e0 [* A! O; Z, m<script>
) v9 |1 @; |9 a8 r3 n$ x* Z pimport todoItem from "@/components/item.vue";4 q9 F, R* t0 k' w$ z2 U; a( {2 M
2 r: \8 l$ f, Y+ g& J! ~% Dexport default {
1 P0 w( |& H+ c3 s8 X3 k2 @; o# A8 q* i data: function() {9 b6 l' g( ]1 [4 N" Z6 t
return {
- a! C& B+ R: x$ { List: [],
% X! \8 ~! d- r1 F inputValue: ""
6 @: f6 D2 w; n0 E }; {9 w% B7 P, p3 B' i0 v
},
) \: x- ^/ K5 @3 K- Z) ~ components: {, s2 g6 T, F* v5 l& P2 z4 Y/ z4 s0 e' H
todoItem
4 o7 M; Y+ V8 [. o8 d5 ?+ [2 x },
. M( Y1 o% O3 `/ [" c methods: {
1 C( u! B5 a8 L+ _ submit: function() {" R3 Q& V6 S# K- B; r3 n; i( u
if (this.inputValue != "") {
3 s) ]) |% g) _2 u3 v this.List.push(this.inputValue);
+ j) R8 c- \# |: i" ?6 U1 h' R1 o m }: f# e/ `2 I+ c: t9 Q2 \: e2 T7 A
this.inputValue = "";
1 o$ @, g j" {+ v },
) o- H2 e! U( \' n; U handleDelete: function(index) {
2 }, `- Y% r+ f( \ f this.List.splice(index, 1);2 T( \" S; i9 t/ w+ a' ]/ m$ A
}
' t1 _& s% g6 c2 ~6 p# S& T5 y }! x( g- j! z+ d7 h: C
};6 a+ t' |7 M2 j; e7 G1 s
</script>
& x0 E2 W1 w2 u( `8 s3 X: H4 \. m. d8 z* C; @) n
' ~# k( h) i9 y+ i q. m
, o0 x5 e v& u& M
. X( D) w1 G5 H
( T2 r: `! c. r% A* U8 V& M" G) W" G" D6 |! M9 V: _% `
$ x5 x, w% ~: O0 M8 a4 G
<template>
: f2 v& a- H5 x; a. y <li @click="deleteItem">{{content}}</li>
! \1 k' @* G* M3 u5 b% z* t</template>7 i) t7 m, `; ]7 c: w7 T0 {
1 p/ T3 u7 c9 [8 [2 p& }<script>* \6 ~1 v0 U5 V, `- ^) E
export default {! j) t9 P) Y* y( J; q
props: ["content", "index"],' _2 ^4 F" N$ n
data: function() {- F8 ?. z1 v% i; R, V
return {};
1 R5 x5 S$ d) F$ h8 b9 I; J/ K },* U, ]% @/ `+ }; e! ]* x
methods: {
6 p/ L% v; q) j. [7 Z0 C deleteItem: function() {. q6 u9 y! w9 ~4 G" o% D2 X- a
this.$emit("delete", this.index);% k8 v: c M: |6 I2 k
}
6 B6 n, F# {) n0 ]( o }
0 @! _5 N, M, B$ x: d8 ^$ L: i};4 h/ D; J" Z) N5 I
</script>( z5 S+ P: h% x$ \& |8 M4 y0 X
% C( P' _0 G' V1 | @$ M# y0 |
0 B% w4 ~2 i) l" u+ J
$ P8 ~1 @2 X3 @! i+ d5 J M6 ]% f, r0 f9 H3 D; V* T: z X
|
|