數(shù)組能做到響應(yīng)式的方法:
? *push():在數(shù)組末尾添加元素(可多個(gè))
? *pop():刪除數(shù)組末尾元素
? *shift():刪除數(shù)組第一個(gè)元素
? *unshift():在數(shù)組最前面添加元素(可多個(gè))
? *splice():刪除挽霉,插入庞萍,替換
? *sort():排序
? *reverse():反轉(zhuǎn)
注意: 通過索引值修改數(shù)組中的元素 不是響應(yīng)式的匙赞。this.movies[0]=‘海王’?
? 由于vue內(nèi)部沒有監(jiān)聽通過索引值修改數(shù)組元素谎脯,所以不會(huì)刷新頁(yè)面爪模。
? 建議使用splice替換元素。
? 或者使用Vue.set(this.movies, 0,‘海王’)? //set(要修改的對(duì)象糖驴,索引值霉猛,修改后的值)
過濾器:
? {{item.price | showPrice}}
? filters: {
? ? showPrice(price) {
? ? ? ? ? return ‘$’ + price.toFixed(2)
? ? }
? }
高階函數(shù):
? *filter中的回調(diào)函數(shù)有一個(gè)要求:必須返回一個(gè)boolean值,對(duì)數(shù)組中元素進(jìn)行過濾
? ? ? 當(dāng)返回true時(shí)酷师,函數(shù)內(nèi)部會(huì)自動(dòng)將這次回調(diào)的n加入到新的數(shù)組中讶凉,
? ? ? 當(dāng)返回false時(shí),函數(shù)內(nèi)部會(huì)過濾掉這次的n山孔。
? ? ? let newNums = nuns.filter(function(n){
? ? ? ? ? ? return n < 100
? ? ? })
? *map:對(duì)數(shù)組中元素進(jìn)行相同操作
? ? ? ? let new2Nums = nuns.map(function(n){
? ? ? ? ? ? return n * 2
? ? ? })
? *reduce:? 對(duì)數(shù)組中所有元素進(jìn)行匯總
? ? ? ? ? let total = nuns.reduce(function(pre, n){
? ? ? ? ? ? ? return pre + n
? ? ? ? ? }, 0)
鏈?zhǔn)秸{(diào)用:
? ? let total = let newNums = nuns.filter(function(n){
? ? ? ? ? ? return n < 100
? ? ? ? }).map(function(n){
? ? ? ? ? return n*2
? ? ? }).reduce(function(pre,n){
? ? ? ? ? return pre + n
? ? ? }, 0)
v-model: 表單數(shù)據(jù)雙向綁定
? ?