|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
6 D- l$ f3 }: ^- M2 S% ~
7 K0 t; ~: [* P* U \; z
4 }, B+ U0 X/ e, z" N! k
8 F0 E6 k. {' t9 _$ i7 i<!DOCTYPE html>
5 h* @! N$ j+ z<html lang="en">; _% l3 W- S+ B! r
<head>
7 R% v$ V8 p" W8 w0 E, t <meta charset="UTF-8">: w' ?0 H% E2 L: L3 u9 s
<title>to Do list</title>
" }9 r! q$ b' q8 t, x- [0 T <script src="./vue.js"></script> z! o5 e y" x7 u6 W0 i3 p
</head>
, P2 x. d! _, p0 H% R. q) L1 s! N" g7 S<body>1 F. I3 }5 }8 M! S k
<div id="root">4 @. h2 {, ~( A7 T% _, r
<input type="text" v-model="inputVaule" />% W5 L' Y9 Q; e; u% L9 L, h. n
<button @click="Submit">Submit</button>
' L5 B; A5 @+ z/ x% L <ul>5 t& x2 j0 B8 y% w3 @( }
<todo-item v-for="(item,index) in List" 4 j: x$ Z9 @+ z
:key="index"
2 W N" `4 \7 O$ A( T :content="item" : K- I k. W+ A# Y, x
:index="index"4 m/ a! x( k) h' E
@delete="handleDelete"
. E l2 Y, z( @ >
- p/ ^* g) s) i1 v7 q+ B </todo-item>& e3 l8 h, i6 R
</ul>' b& u" ^: _; c- j
</div>
$ L7 l% I& z7 m [0 K0 _ <script>
. G+ q6 g# N9 O Vue.component('todo-item', {0 G* U3 Y1 @ O4 ?& M: L2 }8 M
props: ['content','index'],
n- ?; \: V2 V- _6 n template: '<li @click="deleteRow">{{content}}</li>',# F# t2 H9 V; K' c; y& a3 M! F. h! A
methods: {
( M0 _* W. K, n! D g8 b deleteRow:function(){
9 t# [( H1 Z; I! X- V this.$emit('delete',this.index);* j+ O' t. H) s1 t u
}3 B. X. W: U' Y. a8 [0 V! M
}# T" a: v2 P$ ?( g4 N
}). t* c9 P" j( Y! N9 n6 Y
new Vue({
. _2 X$ B2 v* i& f el: '#root',# j/ K. I8 U6 x4 B" \
data: {" v4 L3 r/ j" d1 Y
inputVaule: '',
8 U, A$ B$ B2 O# c List: []: B4 R3 g) E( z/ t8 b$ h
},3 _% G$ m+ d4 t ?
methods: {
' ~6 N! K' P" x* x8 } t! C Submit: function () {
. k4 G6 L1 o6 q0 N. U if (this.inputVaule != '') {
. ~* j. ?2 Q: ~$ H' s& f this.List.push(this.inputVaule);
1 X1 Z; o4 K5 E5 Y+ p$ S$ o }6 j5 p! H5 t8 W9 i) T
this.inputVaule = '';; Y( E& x1 E/ k( E5 K
},
7 g( p% L9 o0 z, a handleDelete: function(index) {
# e, O) T, e4 L2 g this.List.splice(index,1);
3 g2 b* b* J) T# m- B }1 |: w3 O8 ?' f# F
}9 l+ F& K. Q* ^3 C0 \( t
})' c% p$ k! ~; \# T3 O3 w
</script>
& _2 C% A ]# q- M' d7 u5 J</body>
) P, X. B9 W$ H% d# x3 c+ N8 x. r6 `</html>
3 p0 K3 O6 i% A) g: @" \8 D& ~. [
2 b: `/ N. x; u+ p
0 |- E3 w9 ~! r# P& z5 P% W |
|