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
942 B

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>3.姓名案例_计算属性实现</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: "三"
},
computed: {
fullName: {
get() {
return this.firstName + '-' + this.lastName
},
set(value){
const arr = value.split('-')
this.firstName = arr[0]
this.lastName = arr[1]
}
}
}
})
console.log(vm)
</script>
</body>
</html>