|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
3 j/ m0 H: q% }# l* j; b! S( \* P7 h) j* E, M* D
" ]- S1 X% g/ [* N6 N Z
: P) m. K: V% e7 _2 {<template>
: a- m7 A2 y# r* U$ H0 A0 } <div id="App">, w. l1 \8 C! s/ B. u' y
<input v-model="inputValue" />
- Q* |* H' h& e7 {( ^) q <button @click="submit">Submit</button>7 \1 v" T J- K( ?; h
<ul>8 L- Y2 f" l* @! }7 \$ `
<todoItem
7 n* E. Z+ Y0 h$ H5 ^* T5 [ v-for="(item,index) in List"
2 O8 O# | Z& v& E1 l8 b7 E% G$ @ :key="index"- E8 w$ K" u* n9 ]% n* g- r! ~
:content="item"
( q( p. I- H# n: G :index="index"
6 k, S& c c( B y @delete="handleDelete"
% w; j: W% r, o9 G7 e* \1 U4 r ></todoItem>
1 I6 q0 J8 D- x, `3 S5 T3 } </ul>
5 V0 @7 t/ g/ r4 V2 ^5 ]7 S' @3 b1 t" D </div>6 q9 h' E: t9 l: N v1 J- O3 O m9 D
</template>: }$ u+ m% p' S8 |( s" N
( [( F: W/ n; _0 {1 @. B S. H8 b<script>
% J2 F& ?9 Z, o1 o3 w0 h( @import todoItem from "@/components/item.vue";
$ V) q/ e8 B; H7 P2 ]/ ]- {, S# G/ y5 w
export default {/ n( Z4 F+ C! p
data: function() {
$ N! y8 V4 Y L( n: I f return {
: T: x$ P; b7 k) a$ ] List: [],3 `: |! ~ v, n
inputValue: ""
; B+ t/ @( m6 D1 }9 [8 g! M7 p' o };
6 R. I2 E9 `5 ^2 L3 l) M },
, v8 K T, y% i& e4 U* R( a components: {+ E: [# v4 D% X0 K- A0 W
todoItem- x3 R# x. ^. T7 B! C& X/ F
},' E C4 ~; O6 W6 H) d& ^
methods: { u6 E/ m4 D; q$ F3 ?
submit: function() {2 x2 @* k3 J6 C* G
if (this.inputValue != "") {
. Q# O" S! T+ Y this.List.push(this.inputValue); O% U# |2 }: ^: q0 S- K5 F
}4 ^# i: c1 ^' T4 X* K
this.inputValue = "";
) |) p) H A; a; s/ Q1 Y7 w# Y },; y5 w. J( {- o
handleDelete: function(index) {
3 k5 y4 M- m- z: E this.List.splice(index, 1);! Y% I8 R4 ~$ v" f( j
}! h) f. F4 J5 a. v, i/ }
}
6 ], Y9 S# B) A8 M( r};
' P l4 U$ X$ Y, i$ _</script>
" {) J( J6 S% d& H! \2 W
6 U) w7 O r8 s1 l5 |1 a8 E
) W7 h7 U7 y9 X% x2 p
; l8 y/ J( t/ Q3 p& S* i9 h
6 \; h0 } b% o/ T! @4 l
( k9 Z' W8 W i! q4 j( H, ~' N0 M9 n0 o) r6 l0 G) f
- s2 A& t. ]; T8 R; B6 K% H<template>* w/ a" v# z5 v& {8 X. f+ w# ?
<li @click="deleteItem">{{content}}</li>6 I4 g% [$ J$ @( \* ~
</template>$ z2 g$ q: c3 _# X4 v
8 E- @' @5 g9 H; p<script>
* {, U5 f9 p3 S2 n J* H; _) Iexport default {
& q2 ?) _( l6 z8 I4 `: N. _ props: ["content", "index"],
* y7 z; ?/ e$ R& f) Y6 C! U4 c data: function() {
: @" |# a: N0 H& K$ D6 O return {};6 @, k! }$ c& e, ~; I# H
},: w, M) d* r( X
methods: {# O7 ?: X* _: f! {1 F: c9 C1 f
deleteItem: function() {
; g- r/ G8 o8 R+ l$ N this.$emit("delete", this.index);" C# ~ g+ w* s6 s, r5 }
}
1 x# p- z* A5 |9 {) q' x% q }
& J/ R8 K" @4 Y; f9 b};
* n' z) r% ^' Z- n6 W</script>
' ]& c' T9 r; ], Q4 S, P" a; l
! k Z1 n* C3 a' g m3 V6 b1 y" j1 i
9 p+ ^: R* V7 L$ d2 T
9 ~+ g" `6 Z! L/ ] |
|