watch 和 computed
/*
业务:
- 当我写好姓和名 , 全称自动显示
目的: 对比 watch vs computed vs methods
methods: 事件
computed: - 有逻辑 2. 要像变量一样使用 , 这个时候选computed
watch: - 有异步操作 2. 开销较大
*/
案例
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script src="../../basic-source/vue.js"></script>
</head>
<body>
<div id="app">
<div>
姓: <input type="text" v-model = "firstName">
</div>
<div>
名: <input type="text" v-model = "lastName">
</div>
<div>
全称 <input type="text" v-model = "fullName">
</div>
</div>
</body>
<script>
new Vue({
el: '#app',
data: {
firstName: '',
lastName: '',
},
computed: {
fullName(){
return this.firstName + this.lastName
}
}
})
</script>
</html>