|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
& j7 _" g' V% L5 w& F* l9 L
2 @. ~# b" s2 y7 a' u
9 D6 K" `6 ?' }! s) g( l
8 S* d; D+ u9 k! m: q<!DOCTYPE html># ?7 Q1 U+ F9 r; D6 l" l. [
<html lang="en"> w2 f3 Y% Z7 \: s9 a
<head>
. k5 z9 y( k- }, j7 @1 R/ ?5 T <meta charset="UTF-8">
, _; n) D1 X/ v# l <title>to Do list</title>, T5 p" }8 {, i+ o
<script src="./vue.js"></script>3 a0 _: ?8 f- y. U" J; o7 c: x
</head># L& h- Y& `4 n% W4 `# f3 i
<body>; ?+ E3 [# A+ S i
<div id="root">
2 R. w0 s% q2 ?/ J2 q* L <input type="text" v-model="inputVaule" />2 X' x( ~+ e2 [& G" o& u; W$ ?6 W
<button @click="Submit">Submit</button>. ]! b* e, M, N4 O4 l
<ul>( `# d7 R* O" p5 b
<todo-item v-for="(item,index) in List"
( N V+ V: k( P/ Q :key="index"
' s. w7 ^3 z0 C" E :content="item" 4 T9 k& u: k8 |9 @9 T
:index="index", r* Y/ g# |, M; O
@delete="handleDelete"
. J5 R% A; I' `8 T7 ` >
1 r+ S0 B/ R& T" T </todo-item>
% v7 n1 q) l# g, ~ </ul>
6 L# @# t& E: G' e </div>5 G5 z. ]1 Q5 U7 i8 ~' E
<script>
6 L' r1 }) C& g1 o Vue.component('todo-item', {
1 k9 @7 t( c0 `2 ~: U props: ['content','index'], r/ J, X+ I! o5 A, }* P
template: '<li @click="deleteRow">{{content}}</li>',5 V0 N) I2 {3 `9 y/ ]' B
methods: {
4 |0 C2 y; y9 J8 \7 b2 ?/ P/ y0 g deleteRow:function(){
( v; @! R* t+ l* L; e& m this.$emit('delete',this.index);
& T! ~5 |- K+ z- [, } }: m! Q" p! X& E! x0 _
}4 A5 {/ H2 x& W. {
})* y, o1 r! d% q- b. M% y j
new Vue({$ Q& ^: T6 b' `0 q' m$ X
el: '#root',6 E& X0 c9 ?) \: D8 X' T8 T
data: {: V0 z/ Z( Y0 ~8 a
inputVaule: '',1 U! w, F# h/ v3 V, R# P
List: []4 t5 B- n, a* t" q: ~& H; k
},0 R, K# n8 e, V
methods: {
" U, H+ n- d6 B4 ~* S8 Z/ V Submit: function () {
; i7 l7 L, @7 | W% T9 O if (this.inputVaule != '') {
+ {8 ?7 l* ^, B: Q% _, Y$ n this.List.push(this.inputVaule);' d1 \, i$ D+ a
}( q/ H/ j- ?7 t- y
this.inputVaule = '';' @" i6 m9 G' Z8 T- I4 Q+ t& e: K
},( L* ? ^3 P4 S2 V7 P! K
handleDelete: function(index) {
$ A; L! Z$ `3 ^ this.List.splice(index,1); ' [) Z5 `; U$ }& G
}" @' \" i8 l O: d
}% l7 u, i7 B# `# {
})
9 v# ?# V( n9 x9 P6 E8 F+ U </script># ^$ D5 M c* u' n8 N* q- ^
</body>
- J* n9 p( f" y</html>
% Q+ {% @; a# p/ n) P( E" `# l3 C7 C7 r. N4 @0 t% p% B4 C
& D8 s3 |* a! j" _
|
|