计算属性(computed)的getter和setter
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了计算属性(computed)的getter和setter相关的知识,希望对你有一定的参考价值。
<!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的主要内容,如果未能解决你的问题,请参考以下文章