您好,登錄后才能下訂單哦!
這篇文章將為大家詳細(xì)講解有關(guān)vue router如何實(shí)現(xiàn)自動(dòng)判斷左右翻頁轉(zhuǎn)場動(dòng)畫效果,小編覺得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。
一 。首先父頁面
home.vue:
<!-- keepAlList是用來動(dòng)態(tài)判斷組件是否需要keep-alive,建議保存到vuex中作為全局變量,至于下方的css動(dòng)畫,看官可以按照喜好自由修改--> <transition :name="transNa"> <keep-alive :include="keepAlList"> <router-view class="child-view"></router-view> </keep-alive> </transition> <style scoped> .child-view { position: absolute; width: 100%; height: 100%; transition: all .5s ease; -webkit-transition: all .5s ease; -moz-transition: all .5s ease; } .rightin-enter, .leftin-leave-active { opacity: 0; transform: translate3d(50% 0, 0); -webkit-transform: translate3d(50%, 0, 0); -moz-transform: translate3d(50%, 0, 0); } .leftin-enter, .rightin-leave-active { opacity: 0; transform: translate3d(-50% 0, 0); -webkit-transform: translate3d(-50%, 0, 0); -moz-transform: translate3d(-50%, 0, 0); } </style>
二 。其次附上我的main.js片段(用來在跳轉(zhuǎn)頁面之前動(dòng)態(tài)設(shè)置轉(zhuǎn)場動(dòng)畫)
main.js:
//進(jìn)入路由之前設(shè)置攔截器 let noLoginList = ["login", "register", "forget", "home", "classify", "goodsDetial"]; router.routeInfo.beforeEach((to, from, next) => { let user = sessionStorage.getItem('user'); //如果要去登錄頁面 if (noLoginList.indexOf(to.name) >= 0) { if (!user || user == '') { //未登錄的狀態(tài)通行 next(); return; } else { if (["login", "register", "forget"].indexOf(to.name) >= 0) { //已登錄的狀態(tài)去首頁 next({ name: 'home' }); return; } else { //已登錄的狀態(tài)去首頁 next(); return; } } } else { //去登錄頁面以外的頁面(以下是本文關(guān)鍵代碼) if (user && user != '') { //判斷是否為需要緩存組件,如果是添加組件名到數(shù)組 if (to.meta.keepAlive) { const toName = to.name; let keepLi = store.getters.getKeepAlList; keepLi.indexOf(toName) < 0 ? keepLi.push(toName) : ''; store.commit('SET_KEEPALLIST', keepLi); } //根據(jù)路徑名深度設(shè)置轉(zhuǎn)場動(dòng)畫類型 store.commit('SET_TRANSNA', (to.path.split('/').length < from.path.split('/').length ? 'leftin' : 'rightin')); next(); } else { let toWhere = router.nameList.indexOf(to.name) >= 0 ? to : {name: 'home'}; next({ name: 'login', params: { jumpTo: { name: toWhere.name, params: toWhere.params, query: toWhere.query, }, } }); } } });
關(guān)于“vue router如何實(shí)現(xiàn)自動(dòng)判斷左右翻頁轉(zhuǎn)場動(dòng)畫效果”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,使各位可以學(xué)到更多知識,如果覺得文章不錯(cuò),請把它分享出去讓更多的人看到。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。