计算属性的getter和setter
程序员文章站
2024-02-20 15:45:40
...
<!DOCTYPE html>
<html>
<head>
<title>计算属性的getter和setter</title>
<script src="./vue.js"></script>
</head>
<body>
<div id='app'>
{{fullName}}
</div>
<script>
var vm = new Vue({
el:'#app',
data: {
firstName: "Dell",
lastName: "Dll"
},
computed: {
fullName: {
get: function() {
return this.firstName + " " + this.lastName;
},
set: function(vaule) {
var arr = vaule.split(" ");
this.firstName = arr[0];
this.lastName = arr[1];
}
}
}
})
</script>
</body>
</html>
上一篇: js 定义属性 以及 getter 和 setter
下一篇: Swift中的类和结构体