<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<script src="http://cdnjs.cloudflare.com/ajax/libs/vue/1.0.26/vue.min.js"></script>
</head>
<body>
	<div id="app">
		<newcars makes='Fords' count='0'></newcars>
		<newcars makes='Hondas' ></newcars>
	</div>
	<template id="car-template">
		<h1>{{makes}}{{count}}</h1>
		<div>這裡有新車</div>
		<button @click='votecar'>投我</button>
	</template>
	<script type="text/javascript">
		Vue.component('newcars',{
			template:'#car-template',
			props:['makes','count'],
			methods:{
				votecar:function(){
					this.count++;
				}
			}
		});
		var vm = new Vue({
			el: "#app",
		})
	</script>
</body>
</html>

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<script src="http://cdnjs.cloudflare.com/ajax/libs/vue/1.0.26/vue.min.js"></script>
</head>
<body>
	<div id="app">
		<newcars makes='Fords' :count='count'></newcars>
		<newcars makes='Hondas' :count='count'></newcars>
		<!-- 只要是html的屬性,就要用v-bind,簡寫是一個冒號 -->
	</div>
	<template id="car-template" >
		<h1>{{makes}}{{count}}</h1>
		<div>這裡有新車</div>
		<button @click='votecar'>投我</button>
	</template>
	<script type="text/javascript">
		Vue.component('newcars',{
			template:'#car-template',
			props:['makes','count'],
			methods:{
				votecar:function(){
					this.count++;
				}
			}
		});
		var vm = new Vue({
			el: "#app",
			data:{
				count:50
			}
		})
	</script>
</body>
</html>

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 Jerry 的頭像
    Jerry

    Bug倉庫 // 程式日記

    Jerry 發表在 痞客邦 留言(0) 人氣()