|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
Q% n8 {% L% Z' C2 |5 g& H# e+ t: @% C( l X
6 ?' I" z% |4 B9 s" ?8 t1 u
" v8 q4 F2 `/ ^; c# G- @0 l; t5 m<!DOCTYPE html>
, t( I' ?& x2 n9 W, W$ T5 L' u<html lang="en">
8 U; P6 T% ]( i, J3 b<head>/ {3 S" v1 n% @
<meta charset="UTF-8">2 Q* {$ e) l, q* y. N) j2 a
<title>to Do list</title>4 M* r& L6 @/ A( X; V
<script src="./vue.js"></script>
+ H- I I; ^4 v3 C</head>
N5 ~" q, p% ^1 N<body>5 q% u1 a/ g3 F# L2 W. `4 Q
<div id="root">
! p( Y, z8 b4 S2 ?9 J9 S <input type="text" v-model="inputVaule" />& k# ?. S- u8 j% d, S
<button @click="Submit">Submit</button>0 t( N# s# [9 N( V9 q: m* p2 k0 \- y
<ul>9 ?* v7 Q/ v/ P7 y
<todo-item v-for="(item,index) in List" : s9 U2 e; E7 [# W( \1 m2 ^5 m
:key="index" ! B g w3 c; b& ^( |' t
:content="item"
% @3 Z9 Y2 q W! E/ q4 K4 Q l D$ S' n :index="index"9 e+ ]% X, d" ^$ `" N, w5 v
@delete="handleDelete"
3 _, h/ h) S7 x0 m6 F% R6 V >
4 Y1 \. x8 q( l </todo-item>7 ]+ X& _! O3 l: o
</ul>
2 l$ _6 O* L2 ^! a </div>
( j) `$ M0 C$ s$ |3 X <script>
6 q" y- [5 T y" X+ F, M Vue.component('todo-item', {
! o" D! T7 p% X props: ['content','index'],/ V1 z0 B- ]" o6 y/ q
template: '<li @click="deleteRow">{{content}}</li>',$ Z# B" F" t/ O' m
methods: {/ @' W5 m# |3 e( |6 ]8 M; Y
deleteRow:function(){- Y% ]4 \9 P* a
this.$emit('delete',this.index);9 }! f6 h+ o+ `4 T$ v
}
- I& R! a7 R5 E# _1 T8 w" o }* B6 X/ U. K: B4 A0 V
})
! U9 y3 ]& r7 M3 q: q6 {1 f3 x6 w new Vue({
; F; Y4 _- Q- t7 {. I3 p el: '#root',3 m9 e# e! u/ z
data: {- P! {8 m1 H# S
inputVaule: '',
8 `( D& s6 ?5 V J3 B List: [], R/ g; B' O1 y% O$ g' Y0 v+ A
},
- w2 _4 [6 D" S6 \. ~ methods: {
' j _, d) e) p5 r$ ~ S( r Submit: function () {4 S* P0 t% w' ?% X# i: C2 K
if (this.inputVaule != '') {
& g" t( w$ }7 r, S& c* m# F7 `% V this.List.push(this.inputVaule);& A, f, o' y+ t1 f) R: `* U
}6 j0 N& g- U( q: _- K! P; l- D
this.inputVaule = '';
6 V$ k' t5 P* n- D' n },1 f# H6 l4 U: p" T9 }: ]& k
handleDelete: function(index) {
9 v4 q! I7 Y$ A7 C, E this.List.splice(index,1); # {' L. C7 q: Z: ^1 _) W
}
3 L# e/ V8 ^% O5 O) T5 A% v8 i2 r }6 g* v; L/ F) e0 y8 |# M6 l
})+ e% Q* H9 `1 G! F) h, U/ C
</script>
* @4 p+ \/ D" g9 v% M</body>
0 b" H- U1 u7 y3 b4 D8 i: ?</html>, S0 ~2 [8 O; t- F4 j$ I$ t c
! M0 ]3 _6 [8 O2 Y4 U& Z+ y
# i8 [, S4 K2 f' J& L
|
|