Vue-computed的set和get
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> </head> <body> <div id="app"> {{fullName}} {{age}} </div> </body> <script type="text/javascript" src="./vue.js"></script> <script> var app=new Vue({ el:'#app', data:{ firstName:'li', lastName:'zhao', age:18 }, computed:{ fullName:{ get:function(){ return this.firstName+' '+this.lastName }, set:function(value){ var arr = value.split(' '); this.firstName = arr[0]; this.lastName = arr[1]; }, } } }) </script> </html>