<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div id="app">
姓 <input type="text" v-model="firstName"> <br><br><br>
名 <input type="text" v-model="lastName"> <br><br><br>
完整 <span>{{fullName}}</span> <br>
</div>
</body>
<script src='../js/vue.js'></script>
<script type="text/javascript">
Vue.config.productionTip = false
const vm = new Vue({
el: '#app',
data:{
firstName:"哈",
lastName:"黑",
fullName:'哈黑'
},
// computed:{
// fullName(){
// return this.firstName + this.lastName
// }
// }
watch:{
// firstName(val) {
// this.fullName=val + this.lastName
// },
// 场景 5s后 修改姓
firstName(val) {
setTimeout(() => {
this.fullName=val + this.lastName
}, 5000);
},
lastName(val) {
this.fullName=this.firstName+val
},
}
})
</script>
</html>