|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
6 l+ A& U: T' Z3 c
0 e7 _9 ?$ \. O0 L2 n! q
& K6 x6 e3 M- t- M) ^7 y! K
|" X+ z( T# X8 W: v7 o<template>5 F) B8 R0 z8 k6 q* u! n/ Z
<div id="App">
8 q& d9 U. c8 f u* X3 {2 K' D! i <input v-model="inputValue" />' Y1 [$ t4 r( }7 _
<button @click="submit">Submit</button>
' P% W. e! V$ q7 l- [; R% g4 @7 @" y <ul>! x( f& V3 O5 S* u
<todoItem
/ @& _$ B: k0 e2 a+ X v-for="(item,index) in List"
x+ p1 v! w2 @7 A, Z% o5 c2 a; q :key="index"
4 i) X) j9 @5 f" M9 ]* `. |4 M :content="item"" I, W% w$ M! U* |2 D5 @2 `) T
:index="index": R k8 I) t2 I3 x# O
@delete="handleDelete"
# M9 } w7 M. R- ]" L ></todoItem>8 y$ U' A) f* H- I; q( k
</ul>9 {7 e9 o7 J) z& V+ {
</div>8 T/ i. M0 g5 H2 Z2 K
</template>3 s! @) N6 y W
[, R* X+ e" h. M) L<script>
7 t* |: Q" B |% h. Aimport todoItem from "@/components/item.vue";& ?2 [( M- W( H+ y; q
$ |9 O; ?: d0 [% ~! o; a, W
export default {
8 w( V) w/ |1 t data: function() {3 g# A a& O" o6 L' e. G% S
return {
& R7 P- N# ^$ a0 E: N; i: _ List: [],3 e- k9 g+ w+ N" U5 |) p
inputValue: ""9 p% w8 U$ \! B% g A& @1 R
};/ c- s5 ]6 F' y) F/ [
},
/ w- m+ |' E3 i B6 F0 X4 ? components: {
3 ~/ k' q) E& R7 Y/ D" m. r todoItem0 O# i8 I& ]' R3 n2 I1 y* A
},
0 H1 F; D5 `$ U% M v$ S methods: {
6 x+ E% G3 f+ w9 m submit: function() {2 Y- ^4 ~& F+ v# Z0 M! r$ m- \0 [
if (this.inputValue != "") {
5 R7 r4 J0 @9 w5 d: h B8 e" L- e this.List.push(this.inputValue);
0 l1 {, M8 W7 ] }/ F/ Q4 F4 f$ R& F( Y! m% o
this.inputValue = "";! q$ j! }; m; [! Y$ F
},5 ^/ Y/ G2 q' G3 {$ }5 g' J; M y
handleDelete: function(index) {
6 X. }0 l: G- @1 I! G+ @% x this.List.splice(index, 1);: z7 \# {" m0 E) |: t3 e2 }! S' c
}$ s2 A4 M7 }1 H" N/ h
}
v, R, b6 d2 P+ U- F' b};
' @1 r# f5 o* b' [</script>
. U) x0 b' [5 S3 s+ E( ~% x# F* a
" B' Q* E, H" H/ H
3 Z; t6 l) c2 b* q/ w
' [0 V$ c8 A9 j+ G" r
( [; g: a8 h: U, B8 H& X3 O7 X( h+ ]4 J
& g9 }% J8 t3 z3 R" J. a0 y
9 ^/ t" W) u' P# [, [; M- v<template>
6 f2 B& j& x' B <li @click="deleteItem">{{content}}</li>$ P& S" y+ `! c' l* T, Z& M. F
</template>
% f4 V4 f4 U/ d# _ k8 W5 e1 n( x3 I3 E3 v# F
<script>
2 J; W0 u+ y: _/ Dexport default {/ i1 }& ?; \; I0 q. A6 s" c5 m7 {3 E
props: ["content", "index"],
, a7 J3 }0 O7 w, k8 z data: function() {
, P- q, r& L- [ return {};
& l) f; Q- {/ l8 T( n },
; u% e/ `8 B0 I( s methods: {. R+ Z: m) m. i
deleteItem: function() {
9 k( ?7 W9 n2 @ this.$emit("delete", this.index);
: r9 c4 e9 X& d- A }
# ^9 C6 N! s2 R+ ^" x3 w' Q5 o4 M }
, ]1 s7 k$ o2 j2 N( m# m& z" a};
6 Z" N7 ] {- \% f1 n</script>
2 K. F8 [5 w. {9 r
1 [* f# `0 j1 l, X+ @
' M( N: P/ h- _, k3 d: g# [$ T# E
$ s4 q0 R9 @6 ]: }3 G) F |
|