<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div id="demo">
姓:<input type="text"placeholder="First Name" v-model="firstName"><br>
名:<input type="text"placeholder="Last Name" v-model="lastName"><br>
1:<input type="text" placeholder="Full Name1" v-model="fullName1 "><br>
2:<input type="text" placeholder="Full Name2" v-model="fullName2 "><br>
3:<input type="text" placeholder="Full Name3" v-model="fullName3"><br>
</div>
</body>
<script type="text/javascript" src="vue.js"></script>
<script type="text/javascript">
const vm= new Vue({
el:'#demo',
data:{
firstName:'a',
lastName:'b',
fullName2:'a b'
},
computed:{
fullName1(){
return this.firstName+" "+this.lastName;
},
fullName3:{
get(){
return this.firstName+" "+this.lastName
},
set(value){
const names=value.split(' ')
this.firstName=names[0]
this.lastName=names[1]
}
},
},
watch:{
firstName: function (value) {
console.log(this);
this.fullName2=value+" "+this.lastName
}
}
})
vm.$watch( 'lastName',function (value) {
this.fullName2=this.firstName+" "+value;
})
</script>
</html>
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交