标签:相关 compute charset amp 高效 dev += com name
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <script src="https://cdn.jsdelivr.net/npm/vue"></script> <title>Vue中计算属性</title> </head> <body> <div id="app"> <div> <label>长:</label> <input type="text" v-model:value="length2"> </div> <div> <label>宽:</label> <input type="text" v-model:value="width2"> </div> <div> 面积:{{area}} </div>注:v-model:value是将该输入框的值与data中的值进行绑定。 <h4>计算属性set:</h4> <div> <label>省:</label> <input type="text" name="province" v-model:value="province"> </div> <div> <label>市:</label> <input type="text" name="city" v-model:value="city"> </div> <div> <label>区:</label> <input type="text" name="district" v-model:value="district"> </div> <div> <label>详细地址:</label> <input type="text" v-model:value="address"> </div> </div> <script> new Vue({ el: "#app", data: { length2: 0, width2: 0, province: ‘‘, city: ‘‘, district: ‘‘, }, computed: { area() { return this.length2 * this.width2 }, address: { get() { let ret = ‘‘ if (this.province) { ret += this.province + ‘省‘ }; if (this.city) { ret += this.city + "市" }; if (this.district) { ret += this.district + "区" } return ret }, set(value) { let ret = value.split(/省|市|区/) if (ret && ret.length > 0) { this.province = ret[0] } if (ret && ret.length > 1) { this.city = ret[1] } if (ret && ret.length >2){ this.district = ret[2] } } } } }) </script> </body> </html>
标签:相关 compute charset amp 高效 dev += com name
原文地址:https://www.cnblogs.com/xshan/p/12334927.html