You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
929 B
39 lines
929 B
2 years ago
|
<!DOCTYPE html>
|
||
|
<html lang="en">
|
||
|
<head>
|
||
|
<meta charset="UTF-8">
|
||
|
<title>4.姓名案例_计算属性简写</title>
|
||
|
<script type="text/javascript" src="../vue.js"></script>
|
||
|
</head>
|
||
|
<body>
|
||
|
<div id="root">
|
||
|
姓:<input type="text" v-model="firstName"> <br>
|
||
|
名:<input type="text" v-model="lastName"> <br>
|
||
|
姓名: <span>{{fullName}}</span>
|
||
|
</div>
|
||
|
|
||
|
<script type="text/javascript">
|
||
|
const vm = new Vue({
|
||
|
el: '#root',
|
||
|
data: {
|
||
|
firstName: "张",
|
||
|
lastName: "三",
|
||
|
fullName: "张-三"
|
||
|
},
|
||
|
watch: {
|
||
|
firstName(newValue){
|
||
|
setTimeout(()=>{
|
||
|
this.fullName = newValue + '-' + this.lastName
|
||
|
}, 1000)
|
||
|
|
||
|
},
|
||
|
lastName(newValue){
|
||
|
this.fullName = this.firstName + '-' + newValue
|
||
|
}
|
||
|
}
|
||
|
|
||
|
})
|
||
|
console.log(vm)
|
||
|
</script>
|
||
|
</body>
|
||
|
</html>
|