Vue2
<template>
<div>{{ fullName }}</div>
</template>
<script>
export default {
data() {
return {
firstName: 'Foo',
lastName: 'Bar',
}
},
computed: {
fullName() {
return `${this.firstName} ${this.lastName}`
},
fullName: {
get() {
return `${this.firstName} ${this.lastName}`
},
set(val) {
const [firstName, lastName] = val.split(' ')
this.firstName = firstName
this.lastName = lastName
}
}
}
}
</script>
小于 1 分钟