vue練習4
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>計算屬性與偵聽器</title>
<!-- <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> -->
<!-- <script src="https://unpkg.com/vue"></script> -->
<script src="js/vue.min.js"></script>
</head>
<body>
<div id="root">
姓:<input v-model="lastName">
名:<input v-model="firstName">
<div>{{fullName}}</div>
<div>{{count}}</div>
</div>
<script type="text/javascript">
new Vue({
el: "#root",
data:{
lastName: "",
firstName: "",
count: 0
},
computed:{
fullName:function() {
return this.lastName + " " + this.firstName;
}
},
watch:{
fullName:function() {
this.count++;
}
}
})
</script>
</body>
</html>