<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="./vue.js"></script>
<!-- <script src="http://cdn.staticfile.org/vue/2.6.10/vue.common.dev.js"></script> -->
</head>
<body>
<div id="app">{{fullName}}</div>
<script type="text/javascript">
var vm = new Vue({
el: "#app",
data: {
firstName: "Tom",
lastName: "Cat"
},
computed: {
/*fullName: function() {
return this.firstName + " " + this.lastName
}*/
fullName: {
get: function() {
return this.firstName + " " + this.lastName
},
set: function(value) {
var arr = value.split(" ");
this.firstName = arr[0];
this.lastName = arr[1];
console.log("我是" + value)
}
}
}
})
</script>
</body>
</html>
计算属性(computed)的getter和setter
原创文章标签 计算属性的getter和setter 文章分类 JavaScript 前端开发
©著作权归作者所有:来自51CTO博客作者梁十八的原创作品,请联系作者获取转载授权,否则将追究法律责任
上一篇:计算属性,方法与侦听器
下一篇:Vue中的样式绑定
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
Java 接口请求与文件流处理
JAVA 请求响应中的文件流处理方法
Java 文件流 java -
Vue中computed用法
Vue中computed用法
vue.js javascript 前端 sed ci -
Vue中computed与watch
computed (计算属性)支持缓存,只有依赖数据发生改变,才会重新进行计算不支持异步,当computed内
computed watch computed watch 数据 ecmascript