|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
5 s1 \1 s+ k- C! U0 v' j! I$ `/ [
( O# \! G3 [) W/ \9 e/ ]2 p
0 Q" L* g& C# @- ?5 D, |+ _6 w, i' ~( \4 |5 o
<!DOCTYPE html>' U, _7 {! K: Q b- Z
<html lang="en">5 q- W0 n' ~0 M2 P# _" I3 U( a
<head>/ I8 w# e% h' U
<meta charset="UTF-8">
' O0 |1 T$ Y# P/ i' P <title>to Do list</title>. O8 T t# Z! M- p8 ~
<script src="./vue.js"></script>
" Z7 B. X2 p' G9 A: D</head>
+ r6 z3 N/ B6 Z9 `8 V. s<body>
: J: H- r( W0 U+ @' a% \: ]4 c7 Q <div id="root">' v3 S( `4 C3 W- ^: B9 q o
<input type="text" v-model="inputVaule" />3 k' j0 ]7 q, F b4 K: }4 N9 q8 r
<button @click="Submit">Submit</button>
6 u+ E; r0 o7 T( S! y7 E% o7 r <ul>0 q# I2 _6 s$ D6 z5 l, N/ L6 `
<todo-item v-for="(item,index) in List"
) ~: N% o$ _5 f1 i( _( E :key="index"
0 a3 K! V5 [! R l! @( ? :content="item"
, {# m0 ]( D6 ^6 w* ~) L5 X! X :index="index"
9 A6 v: l* |* z5 a* P) } @delete="handleDelete"
T. O( D4 j4 H4 Q' z >
7 r9 W/ j% ~+ T3 j </todo-item>1 e' _# [4 I3 J3 K3 S* J# U
</ul>, ?! W7 A) q* j( n, I/ @" ^; ^+ k. l
</div>: @8 a& \5 ?# @; a8 r9 h
<script>
* @. H: m- P: h" z% E+ N2 O Vue.component('todo-item', {2 Q! x2 E |* }2 q
props: ['content','index'],) F" c/ w6 G6 K) q
template: '<li @click="deleteRow">{{content}}</li>',$ @5 X4 l! ^0 \; |" Y' q$ Z
methods: {
! A( ~5 ~9 E4 `. y deleteRow:function(){
& Z' @/ w( }; P" I; A this.$emit('delete',this.index);
2 M5 Y5 j& t9 L) H0 d+ ~) X9 o }, l, w3 R2 G+ |4 u0 O N
}
4 ~: N- l2 T# d })
" }4 M1 B& Z3 ?5 B1 I- G4 ]$ D& a new Vue({
4 B/ p5 h6 B2 V! U, A4 s3 e/ m el: '#root',+ L$ p) ?; I9 s3 @
data: {% {; Q, Z' \ `' }! ]! |
inputVaule: '',% B. d0 W9 Z+ R: x+ ?
List: []
- [$ v% i# c& y Q/ J6 M2 a& A },
. K7 _& W( `& a methods: {1 K- m& y' W8 ?" o# W1 A# i+ |
Submit: function () {7 E6 l) ~1 t4 M4 y
if (this.inputVaule != '') {2 L) P+ n, P" z4 j
this.List.push(this.inputVaule);
( v- _" x. Q. _2 H% B$ y6 t }
) l+ m3 ?6 G9 Q# Z/ {' ~( u this.inputVaule = '';: {' W* H* ~8 ~# |5 D& F
},
" z/ O" j+ b! Z; C) N) ~8 h2 V* S handleDelete: function(index) {$ V7 V" L8 a: b, o( H
this.List.splice(index,1); % W' C& F" ~; u3 s
}
% g3 {& T( p* M# S. T }
. g, u5 A9 R9 N" X7 n })
/ \* s) a) L+ O6 e& I, Y$ v+ |: D2 ^ m4 H </script>% u. ]- K; g% X+ V
</body>+ K7 ]! K7 L/ t; H
</html>
1 w# a. a9 r. E$ ?, Q3 }- O3 Q8 |
0 L9 ?+ M% U. z& i
|
|