這篇文章主要介紹vuejs如何制作背景淡入淡出切換動(dòng)畫(huà),文中介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們一定要看完!
安裝好vuejs之后,在components里添加Background.vue
代碼如下
圖片的json數(shù)據(jù)如下
[ { "fileName" : "0.jpg", "imgURL": "static/bg/0.jpg" }, { "fileName" : "1.jpg", "imgURL": "static/bg/1.jpg" }, { "fileName" : "2.jpg", "imgURL": "static/bg/2.jpg" }, { "fileName" : "3.jpg", "imgURL": "static/bg/3.jpg" }, { "fileName" : "4.jpg", "imgURL": "static/bg/4.jpg" }, { "fileName" : "5.jpg", "imgURL": "static/bg/5.jpg" }, { "fileName" : "6.jpg", "imgURL": "static/bg/6.jpg" } ]
如果路由不會(huì)的話看一下網(wǎng)上的資料
碰到的問(wèn)題
1.在vue中想直接讓頁(yè)面加載時(shí)運(yùn)行函數(shù)的話將函數(shù)放在mounted對(duì)象里面。
2.函數(shù)放在methods 中
vue-resource用法 //用來(lái)獲取圖片的json數(shù)據(jù) this.$http.get(url).then(response =>{ console.log(response.body); },response =>{ console.log(response.body); }); }
4.用vue-resource時(shí)需要把
import VueResource from 'vue-resource' Vue.use(VueResource);
寫(xiě)到main.js中去
5.mounted函數(shù)中,需要將運(yùn)行函數(shù)放在
this.$nextTick(function () { ......... })
中
6.在vue中用velocity-animate
npm install velocity-animate --save -dev
在main.js中加入
import Velocity from 'velocity-animate'
7.多圖片循環(huán)過(guò)度效果
這里研究了很久,頁(yè)面進(jìn)去之后會(huì)直接從leave函數(shù)開(kāi)始運(yùn)行,不是想象的從beforeEnter開(kāi)始。后來(lái)終于弄清楚為什么了,把show: true改成show: false,則可以讓頁(yè)面從beforeEnter前開(kāi)始。
這個(gè)是參照vuejs的手冊(cè)的,http://cn.vuejs.org/v2/guide/transitions.html這里是關(guān)于過(guò)度效果的所有方面的東西。感覺(jué)能省很多代碼。
以上是“vuejs如何制作背景淡入淡出切換動(dòng)畫(huà)”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對(duì)大家有幫助,更多相關(guān)知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!