vue一些語法

1. 關(guān)于vue路由切換總是默認(rèn)添加一個class router-link-exact-active

<router-link :to="'/'" tag="a" active-class="active" class="scrolly active">個人中心</router-link>

對應(yīng)生成的HTML代碼為:

<a data-v-69d72528="" href="#/" class="scrolly active router-link-exact-active active">個人中心</a>

2. Vue2路由動畫效果實(shí)現(xiàn)

參照vue官網(wǎng)的過渡劫持
動畫效果主要是由 css3 來實(shí)現(xiàn)的。
請參照例子

<template>  
  <div id="app">    
    <transition :name="transitionName">  
      <router-view class="child-view"></router-view>  
    </transition>    
  </div>  
</template>  
  
<script>  
  
export default {  
  name: 'app',  
  data () {  
    return {  
      transitionName: 'to'  
    }  
  },  
  mounted () {  
  },  
  //監(jiān)聽路由的路徑,可以通過不同的路徑去選擇不同的切換效果  
  watch: {  
    '$route' (to, from) {  
      if(to.path == '/'){  
        this.transitionName = 'to';  
      }else{  
        this.transitionName = 'from';  
      }  
    }  
  }  
}  
</script>  
  
<style>  
.child-view {  
  position: absolute;  
  left: 0;  
  top: 0;  
  width: 100%;  
  height: 100%;  
  transition: all .5s cubic-bezier(.55,0,.1,1);  
}  
.from-enter, .to-leave-active {  
  opacity: 0;  
  -webkit-transform: translate(30px, 0);  
  transform: translate(30px, 0);  
}  
.from-leave-active, .to-enter {  
  opacity: 0;  
  -webkit-transform: translate(-30px, 0);  
  transform: translate(-30px, 0);  
}  
</style>  
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 轉(zhuǎn)載 :OpenDiggawesome-github-vue 是由OpenDigg整理并維護(hù)的Vue相關(guān)開源項(xiàng)目庫...
    果汁密碼閱讀 23,404評論 8 124
  • 屬于我現(xiàn)在的生活,并不知道它有什么不好,有點(diǎn)被動的生活,不拒絕喜歡自己的人,不主動打擾自己喜歡的人。做好自己本分的...
    我的少女生活閱讀 241評論 0 0
  • 今天的月亮很圓,很亮,眼前的路燈與月光比起來十分的暗淡。我慢悠悠的靠在涼亭里,感受著夜風(fēng)徐徐吹過,感受這寒冷的風(fēng)帶...
    白森丶閱讀 150評論 0 0
  • 2017年12月22日 星期五 晴 九月份來的簡書,算算已經(jīng)三個多月了。 我一直在找一個地方,一個只屬于我自己的地...
    白于斯閱讀 266評論 5 4

友情鏈接更多精彩內(nèi)容