abstrait:在文本框輸入輸入數(shù)字 和返回下面<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>加法器</title> &l
在文本框輸入輸入數(shù)字 和返回下面
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>加法器</title> </head> <body> <div id="box"> 加數(shù):<input type="text" v-model="addend"> <br> 被加數(shù):<input type="text" v-model="summand"> <br> <h3>和:{{and}}</h3> </div> <script src="js/vue.js"></script> <script> new Vue({ el: '#box', data: { addend: '0', summand: '0', and: 0 }, // 偵聽器:實時監(jiān)測頁面中數(shù)據(jù)的變化,實時更新數(shù)據(jù)模型中的屬性,并完成指定的動作 watch: { // Vue是面向數(shù)據(jù)編程,偵聽器當然也是面數(shù)據(jù),所以watch中偵聽的屬性必須是頁面中的變量 addend: function () { this.and = parseInt(this.addend) + parseInt(this.summand); console.log(addend); }, summand: function () { this.and = parseInt(this.addend) + parseInt(this.summand); } } }); </script> </body> </html>
Professeur correcteur:天蓬老師Temps de correction:2019-01-28 11:58:58
Résumé du professeur:雙向綁定是mvvm設(shè)計模式的基本特征, vue做到了, 而且很簡單