abstrait:<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width,
<!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>整數(shù)相加的小案例</title> </head> <body> <div id="box"> <input type="text" v-model="add1"> <input type="text" v-model="add2"> <h3>{{sum}}</h3> </div> <script src="js/vue.js"></script> <script> new Vue({ el: '#box', data: { add1: '', add2: '', }, computed: { sum:function(){ return Number(this.add1) + Number(this.add2) } } }) </script> </body> </html>
v-model 指令可以實現(xiàn)雙向綁定:用模板中的變量來更新模型中的變量
編寫兩個數(shù)求和的函數(shù),函數(shù)名稱為computed
注意將字符串轉換成數(shù)值用Number,其中這個字符串只能是數(shù)字組成
Professeur correcteur:韋小寶Temps de correction:2019-03-12 17:53:14
Résumé du professeur:學習了偵聽器是不是感覺簡單多了 遠遠比js實現(xiàn)要方便的多的多