|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
( T' p$ k4 s2 A ~* p3 O9 y$ H# ]# K$ d
( X; @. t, G" \ A/ w
9 S7 u) C7 C8 M, n% d. S2 k
<template>
4 N* I) ^# E6 U) y <div id="App">% z+ U! V4 N1 n( P. Z
<input v-model="inputValue" />" b, Y5 g6 P7 f) G; O: A# \
<button @click="submit">Submit</button>
$ p) ?4 R: C' P) P5 e' r M% C8 [ <ul>
1 S9 m6 ^# ]: M <todoItem
( K( w \! G3 P& c7 y7 B v-for="(item,index) in List"
' \: U* d5 r9 Z( m0 P) f+ R: b :key="index"% N$ C) t. a# k7 v7 H7 K5 L
:content="item"
- y1 U0 v+ x. W! v+ Q: `" n2 [ :index="index"
. R; ~2 B+ Z, ~9 F @delete="handleDelete"
- g5 V; B- P0 z' y3 q4 j ></todoItem>) G$ J K8 d& R" j" D) }9 |* G& R
</ul> _% u( x: m6 c8 P: I8 p" F
</div>5 U3 h0 }8 N& g2 X
</template>+ W4 x$ ]9 O3 K
5 r- e, m& [) q1 |<script>9 |! l9 Z' D$ _1 v0 e- c$ M
import todoItem from "@/components/item.vue";
. q" ]% n% O8 S4 D5 B! V
3 @! i1 X. j1 R. G( G4 u' hexport default {
% A6 L+ \( ~0 R) C" [3 ` data: function() {3 Y- `5 t3 d4 _2 L) f* N
return {
o: k( E0 |' w0 B, c List: [],
# c- D2 K V# t/ f4 f, k) a inputValue: ""6 X- W* e7 e, A$ \$ k' O
};( g% T1 M+ Q W1 O$ p- p
},9 {: [; T" |7 ~
components: {0 R/ q/ Y' O6 B; P- s M0 u
todoItem
+ i* O6 U9 Z/ |; P* f },6 p# L7 l% A$ q- a! Q( `5 L
methods: {
8 d+ b: R, j' t( P submit: function() {
# G0 a; `4 W; W5 ]& c( ]% Z if (this.inputValue != "") { O4 K. \- K7 x# O; ~! d. h2 r
this.List.push(this.inputValue);
* `: F% k, Z6 W8 z0 X }
) L! X0 T& f1 F L- K j4 | this.inputValue = "";
3 E `) @- \$ {# i; P5 @* k },
& v) q$ V' j. r5 O handleDelete: function(index) {$ X1 {' m6 |. i. s" {
this.List.splice(index, 1);* }, i( m, W7 N- W
}) M0 u8 Z. v$ [5 g' c# V& R% d% m: F
}
& C& o( T9 E, Z: T! d. h, Y};% E$ Y% p4 m0 C; u7 W
</script>/ |# |1 U6 Q6 Y; e, [; n& D. f! Y
* R' ^4 G4 s. j$ K+ g
6 D2 n" }2 W5 g* t& _& c& f8 |7 ?, F# y P- D
# i, B R6 ^: q ~% Z2 G' [) ?7 g
! E, S+ v" k h" t3 D' s& @* I @* I
. ^5 s8 |- E; L& X5 X4 b
) G% v. [ ~2 Q5 r8 d, Y: G+ h0 V/ Y<template>
5 V C6 p0 b9 l- V: m <li @click="deleteItem">{{content}}</li>3 o: I4 _8 c& I- }6 p% x
</template>2 f6 {. j$ X" w7 Q: ?! G) e5 \
; r9 X+ ]! {5 u6 |- j. l) R! B
<script>
! K5 J: n8 e# w; eexport default {/ P6 l, w! N* E+ q; X y
props: ["content", "index"],
; g/ z4 ?3 ~8 v9 a; u& E data: function() {
6 s' `# y+ q6 C return {};
$ f, ?: f9 i4 _) i% m! C9 k },
1 q9 B7 E% p0 y3 m methods: {
3 n: `' X& v4 n# o; H& a- m deleteItem: function() {/ a, Y5 b' E! [# f# a" I) _& x
this.$emit("delete", this.index);$ {- }, b8 R+ w3 S
}- l8 d; i; E8 |0 E: Z
}
# S" q* Y( T$ r};0 \ O7 m# [* L4 K( h+ @1 g
</script>* Q* n2 J6 K( X8 m
2 s0 e* E+ T% S0 Z! E6 W2 D
, g4 t; K" |& r- @- B% u; v
. S: }1 v! D- T) Z/ y. G% W0 Y5 @# [/ u$ R
|
|