|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
& G3 c4 |! R! T0 U+ o, P. Y7 n' Q& ~$ T9 _5 }/ T u
$ m8 W: Q/ d+ y! w2 m8 C8 G) r3 X
& V4 L) f* b8 T2 c
<template>8 D) Z1 D, l* _2 y% U+ w
<div id="App">
! i; {, {" b* Y: ` <input v-model="inputValue" />8 C% U1 e0 s1 C$ t
<button @click="submit">Submit</button>
9 m7 n# R n# ?/ G# ` <ul>( E! M/ J0 s& l6 m+ e- c7 n
<todoItem
- V' h& J6 K+ I4 J+ J; T) B! u! H Z' _ v-for="(item,index) in List" M% _2 G% E4 Q* S$ V8 F( h
:key="index"5 u2 o, z' ?( F7 @; j
:content="item": ?5 d, O0 j0 U s" B9 X6 [8 O# x* v
:index="index"" c3 {" ?: ]2 ?8 b! j; c) y
@delete="handleDelete"
: J8 [$ M0 g/ }! ] ></todoItem>8 C5 P& L7 S" L$ S! n
</ul>
# K7 K0 J& ~2 e </div>
' t# ^. F/ N4 ]# Z/ {0 _</template>% z" \9 d5 |$ w- N. R- E* L: O/ }
7 T6 M- o, |% W- W9 I& ?# I- u
<script>
3 j2 z. m; e! O( z0 J' ?- Limport todoItem from "@/components/item.vue";
0 ]3 ]1 ~7 M/ X+ }
) f* K( P# t2 T2 d" _) G* |; eexport default {3 A3 |, f2 X& y
data: function() {
: z# X7 Q2 a+ ~' ] return {
/ I! v* F( a( E2 r List: [],! [, g4 |8 x! S
inputValue: ""
0 p( r% M$ g z0 N- _) j3 Z& C2 [ };
N; Y1 I6 {5 j9 F, J },
( S+ O% b6 }! n8 R. ^* X# [ components: {, P1 w$ s: G0 I$ U1 ]9 i8 i3 X0 e
todoItem+ J! H6 v+ W( J/ o2 y" L& A, C% ?& [
},
: o" ?: O/ n, S7 p methods: {
9 v$ I% m! {6 T1 _- H* _6 Z( e submit: function() { Y) D/ G! i1 V& K) J# P
if (this.inputValue != "") {$ m4 |% g8 w: B! F" m, I! H1 l9 [
this.List.push(this.inputValue);
/ j6 l/ T4 r& V' ^ }
* F6 j" [/ @' Q. a. d) X$ Z this.inputValue = "";
: Y8 l5 o4 L0 R& J% G' ` g },: R9 K! s* e6 l; {) q1 Y
handleDelete: function(index) {
5 d( C0 {2 [ D7 S+ J2 I" B this.List.splice(index, 1);
' c* s5 e6 b+ [2 r5 X; E1 h }0 k1 s( S) @* [. E. }* g
}
! F3 \, n f9 ^! }};* [0 ~, d6 L+ Y+ k8 G3 |# p$ T# p
</script>
8 Y& A) c) X5 k% @" b
( u& A$ d/ z. B! P$ N# E& f/ E0 G) ?0 z$ z
9 B% M5 _, Z a7 E
: x0 `6 c! x5 b2 D; y6 H3 v I! ^: ~: g5 {% h B5 Z
I1 K4 A' n2 b# ]( s0 ? D C- _. S& x1 k$ Z, i
<template>5 M3 E, l/ _8 F. N i; ~
<li @click="deleteItem">{{content}}</li>' q) R! W0 [+ [
</template># x+ N# U, t0 X( I0 s
0 M1 O+ j7 [; ]- b+ D- V
<script>( k! h; q( I. U5 D* f, h5 u
export default {
; f+ B" M3 G8 O; N8 j& E' s2 f p props: ["content", "index"],
* G+ t/ ^1 Y p data: function() {! s6 f6 w) x5 N
return {};
0 M& }" E3 B( j6 u2 j },
0 w* ^3 u( G6 L( k methods: {/ D" x2 B! c) Y! F
deleteItem: function() {
5 |2 `( x# R% L4 W, d' A this.$emit("delete", this.index);
+ y+ x* s2 s6 i }
K- v6 T, g' E; U# e+ O }
. P0 q) o8 D) O% p1 z( p: C* U Q: @};
6 v" ^# f1 C$ |) N</script>
$ _3 `+ N" `9 H9 v) h6 b5 @1 D) C) l7 R/ v
# p: P( `3 k; F4 ~* ]# b" q
$ o' B. K6 n& a$ s3 c6 E) i$ r5 N6 r0 K+ C- g7 o) C0 h& r- X
|
|