<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>计算属性的get和set</title>
<script src="js/vue.js"></script>
</head>
<body>
<div id="app">
{{fullName}}
</div>
<script>
var app = new Vue({
el:'#app',
data:{
firstName:"Dell",
LastName:"Lee"
},
/*
计算属性(computed)的getter和setter方法
set函数里面的v值指向的是fullName
get函数返回的值指向的是fullName
*/
computed:{
fullName:{
get:function(){
return this.firstName + " " + this.LastName
},
set:function(v){
arr = v.split(" ")
this.firstName = arr[0]
this.LastName = arr[1]
}
}
}
})
</script>
</body>
</html>
vue.js基础之计算属性的get和set
最新推荐文章于 2022-10-12 20:06:39 发布