源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

Vue Transition实现类原生组件跳转过渡动画的示例

  • 时间:2020-06-28 19:11 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:Vue Transition实现类原生组件跳转过渡动画的示例
最近学习了Vue Transition的用法,感觉这个地方知识点挺多的,而且很重要,所以,今天添加一点小笔记 官方文档:[url=https://cn.vuejs.org/v2/guide/transitions.html]https://cn.vuejs.org/v2/guide/transitions.html[/url] 演示地址:[url=http://www.coderlife.com:4000/#/]http://www.coderlife.com[/url] (请在移动端查看,PC端查看请打开移动端调试模式) [b]前言[/b] 看了挺多Vue的UI框架都不带过渡动画,今天心血来潮,就把自己平时用的动效抽离出来。可直接通过脚手架init模版配合其他UI框架使用,不需要另外进行配置。 [b]原理[/b] 模版中使用了Vue提供的封装组件 transition,配合CSS类名在 enter/leave 的六种不同的状态过渡中切换。 [img]http://files.jb51.net/file_images/article/201708/2017819180436890.png?201771918456[/img] 对于这些在 enter/leave 过渡中切换的类名,v- 是这些类名的前缀。使用 [code]<transition name="my-transition"> [/code]可以重置前缀,比如[code] v-enter [/code]替换为[code] my-transition-enter[/code]。 [b]重写跳转函数[/b]
// 根据具体的跳转类型更改跳转属性值,执行不同的动画
const nextDirection = (direction) => {
 let el = document.getElementById('app')
 if (el) el.setAttribute('transition-direction', direction)
}

router['_push'] = router['push']

// 重写路由跳转方法,设置跳转类型后跳转
router.forward = router['push'] = (target) => {
 nextDirection('forward')
 setTimeout(() => { router['_push'](target) })
}

// 重写路由返回方法,设置跳转类型后跳转到上一页
router.back = (target) => {
 nextDirection('back')
 if (target) {
 setTimeout(() => { router['_push'](target) })
 }
 history.go(-1)
}

[b]How to use[/b]
# init template
vue init CoderLQChou/v-transition-template my-transition-app

# cd project
cd my-transition-app

# install dependencies
npm install

# serve with hot reload at localhost:8080
npm run dev

# build for production with minification
npm run build

仓库地址:[url=https://github.com/CoderLQChou/vue-transition-template]https://github.com/CoderLQChou/vue-transition-template[/url] 以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程素材网。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部