|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
; S8 ]7 B1 i2 G) u6 \
! }; t) ^, `7 q6 ]) c. p$ s6 G6 y* S0 g1 r; R( M& U4 I
* b1 e$ {0 A1 w' ?+ ]2 y<!DOCTYPE html>
8 N' F5 d* K) X: g0 O4 B<html lang="en">0 d8 {; y2 S) S/ I; j: s# @
<head>" Q8 @4 H! `6 j @3 t- Z
<meta charset="UTF-8">
. y6 i* n2 z1 M <title>to Do list</title>
2 w8 D0 d- s0 R/ z4 z. e# Y- f <script src="./vue.js"></script>0 ?$ z, N; e% x; ^* \3 W
</head>1 \8 S; G0 @$ u1 a/ Q6 C( b
<body>
, u% C# J w" G# S( m. H2 W <div id="root"> }9 H! a, X- y) s3 t
<input type="text" v-model="inputVaule" />& X% ^# \! q3 v" _
<button @click="Submit">Submit</button>6 q) M. ~8 l& T) B% Y+ A1 E2 C: K
<ul>
8 p4 t; t3 s, q+ H, h, S <todo-item v-for="(item,index) in List"
5 Y" n; v+ Q( l :key="index"
$ ^; z- V2 l; u7 t2 i& ?" {8 k :content="item"
?5 z9 g% D# [6 {( u, I) n :index="index"
2 r% w) w- @8 }* R7 x( i6 Y @delete="handleDelete"+ @1 q( f a* j4 C1 H: B
>! G; @: i+ z( S8 B
</todo-item>
7 q0 ~1 T; I5 j9 g* Z: ~ </ul>
1 a& q" e5 V8 R7 J# k4 T </div>% a( f5 L5 ^3 z' @2 A9 M' E F( ~$ Y
<script>
2 R2 P {3 a# q1 k/ @ Vue.component('todo-item', {
9 ^* y! F0 p# L6 A, v& o props: ['content','index'],/ i/ N: Q: X% [0 q" X
template: '<li @click="deleteRow">{{content}}</li>',3 X3 f# g& Y3 g4 D; S
methods: {3 [- w) w; N$ Y6 N
deleteRow:function(){- t7 q; {: s* g) [! H. E$ d
this.$emit('delete',this.index);
5 u& q/ B: x; f# G1 t" C& g }) ?7 @, D, U4 [5 o
}( }1 B/ L% r0 v% _1 j- a) U
})
& F; F) K; @1 k new Vue({2 t& |4 B# e( _8 x& n" i
el: '#root',0 J C* i' z7 b1 \1 j- r' T
data: {
6 f1 q8 F8 \8 C6 o2 `/ V inputVaule: '',+ w* m! I9 O; \; Y# k2 R3 f8 o
List: []
4 G! Z+ y, N1 a" u },# k7 }8 A- ~& o* V: r4 }5 p& g
methods: {$ b& k; o3 \: K: r2 U1 H8 r
Submit: function () {; L7 n. G* e+ W+ |( t- A
if (this.inputVaule != '') {! k8 U+ U, |- S3 |2 l
this.List.push(this.inputVaule);$ B3 k* u/ W, L+ q1 {
}" `" |" A7 H% o1 G, E' [! n9 g. w
this.inputVaule = '';1 `( d# S. |7 }. P' Y! ^
},( C( b' i2 g, p% r
handleDelete: function(index) {
0 k7 P# Z' c J2 S {& v6 B this.List.splice(index,1);
0 d. c! Q* R' Q: h$ P- [% {- h }
9 \4 ]# o% J0 \+ C5 k- v }
4 g$ E6 f) W/ C })
5 q5 m- M, c$ Z* q1 o0 L </script>& Y! @+ Y/ E, [ e7 N! m) T; j5 D
</body>
1 B5 s; \. ]1 x1 r8 T$ m</html>
+ n7 g2 J9 v0 v' b% O; u" E0 Z1 s/ w) }/ e T, A! X; t/ x, a8 f
/ t. K# \4 [# X4 p+ D
|
|