1. 程式人生 > >vue基礎學習之componentWv-for.html

vue基礎學習之componentWv-for.html

<style>
		.completed{
			text-decoration: line-through;
		}
	</style>
	<body>
		<script type="text/javascript" src="js/vue.js" ></script>
		<div id="app">
			<task-app :list="tasks"></task-app>
		</div>
		<template id="task-template">
			<ul>
				<li @click="toopposite(task)" v-bind:class="{'completed':task.completed}" v-for="task in list">
					{{task.body}}
				</li>
			</ul>
			</template>
		<script type="text/javascript">
			Vue.component('task-app',{
				template:"#task-template",
				props:['list'],
					methods:{
					toopposite:function(task){
						task.completed = !task.completed;
					}
				}
			})
			var app =new Vue({
				el:'#app',
				data:{
					tasks:[
					{body:'this is first',completed:false},
					{body:'this is second',completed:true},
					{body:'this is lase',completed:false}
					]
				}
			
			})
		</script>
	</body>