<!DOCTYPE html>
<html>
<head>
<title>computed的getter和setter</title>
<meta charset="UTF-8" />
<script src="./vue.js"></script>
</head>
<body>
<div id='app'>
{{fullName}}
</div>
<script>
var vm = new Vue({
el:"#app" ,
data:{
firstName:"Pull" ,
lastName:'Walker'
},
computed:{
fullName: {
//get方法取值 set(value)方法设置 value即为获取到的fullName 如此可以动态设置 所依赖的变量
get:function() {
return this.firstName + ' ' + this.lastName ;
},
set:function(value) {
// console.log(value) ;
var arr = value.split(' ') ;
this.firstName = arr[0] ;
this.lastName = arr[1] ;
}
}
}
})
</script>
</body>
</html>
Vue2.6-computed(计算属性的getter和setter)
最新推荐文章于 2024-10-02 23:15:45 发布