|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
- w0 ~1 L4 s% b. ~ k/ p5 t" m8 Q( W
+ X) [/ k' o u0 u/ x/ }2 I1 j U& M; ` z; }' s
9 k8 T6 T' k* x- Q% J+ D% |<template>) P8 P6 x3 o( [$ `% r/ V
<div id="App">
( X+ {5 k" J/ G2 x1 l5 c! J <input v-model="inputValue" />0 y2 |6 @! n" U3 U
<button @click="submit">Submit</button>" n7 Z* Y! ^- d( c% F4 b
<ul>
: E# p* [. |1 b' S" W <todoItem( ~. l' i9 O! e2 w& t, x
v-for="(item,index) in List"
9 M* M6 {& `: h) |, e) P& T :key="index"- |) t: n( z0 d1 V/ ?( m2 b* ^
:content="item"
# ~4 v. ?! Z0 V7 m" u :index="index"4 e8 R* y8 [( u
@delete="handleDelete"
2 D- F9 u- F! L& S' }% Q _) K6 y ></todoItem>8 U' S$ J1 r* t1 ?+ M# w
</ul>
# p0 U. M, P+ O7 k& x) H7 X </div>
6 g5 O; J4 m3 {0 ^</template>
, ^1 k5 W2 D$ S- f
' P1 A2 _. h% S' r! s) k: x+ q) P, a<script>
8 }8 m2 o* f! N" U! `. a ^import todoItem from "@/components/item.vue";" ^* \7 s+ f! E9 N' n3 ^4 X
. @; N& j- q" d
export default {
+ c; X& S9 P3 g data: function() {
: [ n; `5 ?- V- L return {
$ r0 E% e% k& `2 c( L List: [],& A I# w$ D! w8 @2 R
inputValue: ""6 P8 X. |% c; Q2 s
};9 d1 z* V; \! I4 d* n p
},
1 o H6 o; u/ \ components: {
/ _5 q5 |3 k4 _ todoItem
* Q/ @! N+ O. D* r9 s! T$ n },
! E8 S$ Z/ X0 R6 }0 X methods: {, j9 T- y! M: [" Z$ l
submit: function() {
" X' x% {4 A/ N5 H; [7 c if (this.inputValue != "") {" R7 a& ]) q6 x, t
this.List.push(this.inputValue);3 c2 E+ Y4 |- R$ d: \( L
}- n* g* w! l. `1 U
this.inputValue = "";
* q4 L' J6 n/ `% Z },5 o' n; g* w! N( y
handleDelete: function(index) {
* A _8 A6 l2 Z2 }, R6 }4 c this.List.splice(index, 1);
. K3 E6 B, G* I: X2 b8 ?! V3 @ e$ X* Y }
+ _8 h$ Q7 z4 m+ N }
0 A1 k( ~' \9 T$ K8 {; f; a9 _};, K# Y, `3 B5 b
</script>
. V4 q: P9 I5 w8 ?7 [/ Y# i [( _8 x
/ J' D/ C" A7 I. O
: b f a" `- h+ W4 ~
& @/ O5 C ]+ y5 A: m: `1 N& m, b1 t0 `" }' q# e
# i* P; F5 \2 @' v0 A: @" O
" \$ H, |/ C3 x* L R) Z<template>
5 P% |$ T5 s$ C3 Z% j3 ~5 Q+ K <li @click="deleteItem">{{content}}</li>
. f$ M& z# d" l& z) L</template>$ I1 x7 u, ?# |/ p5 ^
7 P L- s, U- B<script>2 v7 q: l* c) k
export default {9 ^, w% G) V3 g$ i7 k: x. Z+ z
props: ["content", "index"],
% W& J$ t. p) u data: function() {. Z7 q; O& @( M) g1 \. }
return {};
( d6 d4 ?$ h2 [6 ]' R/ @5 q0 @ n },& ]9 h) [6 e0 w# b# ]8 R
methods: {
9 A H; y8 @# J deleteItem: function() {. J4 C( [' `$ t
this.$emit("delete", this.index);
% g4 ]2 r6 Q( g3 P: r- s* E" q }
+ ]" C! S) }$ u( M( S: \ }
! b7 W5 Z# c. l' q0 d3 \};
; ^2 i9 T8 U/ g6 Q</script>
4 \7 b: Y) B4 B7 i# U: Y& p
- ~) f8 Y% M$ Q2 r/ M3 x- J/ B
8 d6 O& t% j) _9 \; Z! n9 ?4 |4 w) P
! O0 J3 V3 T* |! s; t, v |
|