【四二學堂】組件事件(Vue.component:vue系列入門示例之二十六)

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>組件屬性</title>
		<script src="vue.js" type="text/javascript" charset="UTF-8"></script>
	</head>
	<body>
		<div id="app">
			<button-counter title="title1"></button-counter>
			<button-counter title="title2"></button-counter>
			<button-counter title="title3"></button-counter>
		</div>
		<script>
			
			Vue.component('button-counter',{
				props:['title'],
				data:function(){
					return{
						count:0
					}
				},
				template:'<div><h1>hi.......</h1><button v-on:click="clickfun">{{title}}:You click me {{count}}times.</button><div>',
				methods:{
					clickfun:function(){
						this.count++
					}
				}
			})
			
			var vm=new Vue({
				el:"#app",
				data:{
					
				}
			});
			
		</script>
		<style>
			
		</style>
	</body>
</html>

在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章