????:Vue的導(dǎo)入是和jq一樣的方式 創(chuàng)建一個(gè)Vue的實(shí)例 computed是在HTML DOM加載后馬上執(zhí)行的, 如賦值;而methods則必須要有一定的觸發(fā)條件才能執(zhí)行,如點(diǎn)擊事件 <!doctype html> <html lang="en"> <head> <
Vue的導(dǎo)入是和jq一樣的方式 創(chuàng)建一個(gè)Vue的實(shí)例 computed是在HTML DOM加載后馬上執(zhí)行的, 如賦值;而methods則必須要有一定的觸發(fā)條件才能執(zhí)行,如點(diǎn)擊事件 <!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>VueJS實(shí)例:兩個(gè)數(shù)相加</title> <script src="js/Vue.js"></script> </head> <body> <div id="test"> <input type="text" v-model="first"> <input type="text" v-model="second"> <p>{{first}}+{{second}}={{inputNum}}</p> </div> <script> //Vue的導(dǎo)入是和jq一樣的方式 // 創(chuàng)建一個(gè)Vue的實(shí)例 // computed是在HTML DOM加載后馬上執(zhí)行的, // 如賦值;而methods則必須要有一定的觸發(fā)條件才能執(zhí)行,如點(diǎn)擊事件; // watch用于觀察Vue實(shí)例上的數(shù)據(jù)變動(dòng)。對應(yīng)一個(gè)對象,鍵是觀察表達(dá)式,值是對應(yīng)回調(diào)。值也可以是方法名,或者是對象,包含選項(xiàng)。 // 所以他們的執(zhí)行順序?yàn)椋耗J(rèn)加載的時(shí)候先computed再watch,不執(zhí)行methods;等觸發(fā)某一事件后,則是:先methods再watch。 new Vue({ el: '#test', data:{ first:1, second:2, }, computed:{ inputNum:function(){ return parseInt(this.first)+parseInt(this.second) } } }); </script> </body> </html>
?? ???:韋小寶?? ??:2019-01-11 15:27:06
???? ??:寫的很不錯(cuò) 很完整 vue還是很強(qiáng)大的吧 課后記得沒事多練習(xí)哦