vue.js get和set方法使用
阿新 • • 發佈:2018-12-05
vue.js get和set方法使用
================================
©Copyright 蕃薯耀 2018年12月05日
http://fanshuyao.iteye.com/
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>vue.js get和set方法使用</title> </head> <body> <div id="vue-div"> <div>姓:<input placeholder="姓" v-model="firstName"/></div> <div>名:<input placeholder="名" v-model="lastName"/></div> <div>全名:<input placeholder="全名" v-model="getFullName"/></div> </div> <script type="text/javascript" src="../js/vue.min.js"></script> <script type="text/javascript"> var vueObj = new Vue({ el: "#vue-div", data: { firstName : "張", lastName : "三" }, computed:{ getFullName: { get : function(){ return this.firstName + "," + this.lastName; }, set : function(newValue){ var names = newValue.split(","); this.firstName = names[0]; this.lastName = names[1]; } } } }); </script> </body> </html>
================================
©Copyright 蕃薯耀 2018年12月05日
http://fanshuyao.iteye.com/