<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<script src="../vue/vue.js"></script>
<title>学习vue</title>
</head>
<body>
<div id="app">
<div>{{fullName}}</div>
</div>
<script>
var app = new Vue({
el: '#app',
data: {
firstName: 'zhou',
lastName: 'jin',
},
computed: {
fullName: {
//getter
get: function() {
return this.firstName + ' ' + this.lastName
},
//setter
set: function(value) {
var arr = value.split(" ");
this.firstName = arr[0];
this.lastName = arr[1];
}
}
}
})
</script>
</body>
</html>