<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>vue-router之使用transition设置酷炫的路由组件过渡动画效果</title>
<script src="vue.js"></script>
<script src="node_modules/vue-router/dist/vue-router.js"></script>
<link rel="stylesheet" href="animate.css">
</head>
<body>
<div id="demo">
<router-view></router-view>
</div>
<script type="text/x-template" id="home">
<transition enter-active-class="animated rotateIn">
<div>
<li v-for="v in news"> <a href="#" @click.prevent="go(v.id)">{{v.title}}</a>
</li>
</div>
</transition>
</script>
<script type="text/x-template" id="content">
<transition enter-active-class="animated slideInDown">
<div>
<h1>{{field.title}}--{{field.id}}</h1>
<p>
{{field.content}}
</p>
<a href="" @click.prevent="back()">返回首页</a>
</div>
</transition>
</script>
<script>
const notFound = {
template: '<h1>NotFound</h1>'
}
var data = [
{id: 1, title: "php课程", content: "php是个比较牛的技术"},
{id: 2, title: "java课程", content: "java是个比较牛的技术"},
{id: 3, title: "pathon课程", content: "pathon是个比较牛的技术"}
]
const home = {
template: "#home",
data() {
return {
news: data
}
},
methods: {
go(id) {
//var url='/content/'+id; //url第一种写法
//var url={name:'content',params:{id:id}};//url第二种写法
//this.$router.replace(url);//replace()替换历史记录中的跳转: var url = {'path': '/content/' + id};//跳转到详情页 //url第三种写法
this.$router.push(url);
}
}
}
const content = {
template: "#content",
data() {
return {
field: {}
}
},
mounted() {
var id = this.$route.params.id;
for (let k = 0; k < data.length; k++) {
if (data[k].id == id) {
this.field = data[k];
}
}
},
methods: {
back() {
this.$router.go(-1);
}
}
}
let routes = [
{path: '/', component: home},
{path: '/content/:id', component: content, name: "content"},
{path: '/content/3', alias: ['/about']},
{path: '*', component: notFound} ];
//把组件交给路由器:
let router = new VueRouter({routes});
new Vue({
el: "#demo",
router
});
</script>
</body>
</html>

  

067——VUE中vue-router之使用transition设置酷炫的路由组件过渡动画效果的更多相关文章

  1. 【面试题】Vue中的$router 和 $route的区别

    Vue中的$router 和 $route的区别 点击视频讲解更加详细 this.$route:当前激活的路由的信息对象.每个对象都是局部的,可以获取当前路由的 path, name, params, ...

  2. 黑马vue---16、vue中通过属性绑定为元素设置class类样式

    黑马vue---16.vue中通过属性绑定为元素设置class类样式 一.总结 一句话总结: 这里就是为元素绑定class样式,和后面的style样式区别一下 vue中class样式绑定方式的相对于原 ...

  3. 用C3中的animation和transform写的一个模仿加载的时动画效果

    用用C3中的animation和transform写的一个模仿加载的时动画效果! 不多说直接上代码; html标签部分 <div class="wrap"> <h ...

  4. vue中的$router 和 $route的区别

    最近在学习vue的单页面应用开发,需要vue全家桶,其中用到了VueRouter,在路由的设置和跳转中遇到了两个对象$router 和 $route ,有些傻傻分不清,后来自己结合网上的博客和自己本地 ...

  5. Vue中this.$router.push(参数) 实现页面跳转

    很多情况下,我们在执行点击按钮跳转页面之前还会执行一系列方法,这时可以使用 this.$router.push(location) 来修改 url,完成跳转. push 后面可以是对象,也可以是字符串 ...

  6. vue中的router和route有什么区别?

    我只知道前者一般用在跳转路由的时候,push一个url, 而后者则用来存储路由跳转过程中存储的各种数据. 话不多说,这篇博客讲的比较详细,可以参考一下. vue2.0中的$router 和 $rout ...

  7. vue中computed(计算属性)和watch在实现父子组件props同步时的实际区分

    vue中computed和watch的对比是一个很有意思的话题. 看过官网教程以后,我们往往更倾向多使用computed.computed优点很多,却在某些时候不太适用. 今天我们就稍微讨论一下,当我 ...

  8. vue过渡动画效果

    1 过渡基础 1.1 过渡的方式 Vue 在插入.更新或者移除 DOM 时,提供多种不同方式的应用过渡效果. 包括以下工具: 在 CSS 过渡和动画中自动应用 class 可以配合使用第三方 CSS ...

  9. vue实现多个元素或多个组件之间动画效果

    多个元素的过渡 <style> .v-enter,.v-leave-to{ opacity: 0; } .v-enter-acitve,.v-leave-active{ opacity: ...

随机推荐

  1. 20145333茹翔 Exp5 Adobe阅读器漏洞攻击

    20145333茹翔 Exp5 Adobe阅读器漏洞攻击 实验过程 主机为kali的ip地址为:192.168.1.111.靶机windows xp 的ip地址为:192.168.1.110 使用命令 ...

  2. 使用CSP防止XSS攻击

    转载自阮一峰博客:http://www.ruanyifeng.com/blog/2016/09/csp.html 跨域脚本攻击 XSS 是最常见.危害最大的网页安全漏洞. 为了防止它们,要采取很多编程 ...

  3. 解决gvim中php函数提示php_funclist.dict无法生效的问题

    在Windows中, 当打开php文件时, 提示 dicvim(setlocal) unknown option: Files\Vim\vimfiles\dict\php_funclist.dict ...

  4. P4 Tutorials Flowlet Switching

    Github链接: Exercise 2: Implementing TCP flowlet switching P4 Tutorials Flowlet Switching 最近P4社区更新了Tut ...

  5. FOJ-1058-粗心的物理学家

    题目:粗心的物理学家 代码: #include<stdlib.h> #include<iostream> #include<cstdio> using namesp ...

  6. js中一些关于比较左右两边的值的题目

    alert(typeof(NaN)); alert(typeof(Infinity)); alert(typeof(null)); alert(typeof(undefined)); alert(Na ...

  7. js渐隐渐现透明度变化淡入淡出轮播图

    js渐隐渐现透明度变化淡入淡出轮播图.焦点图 一些广告banner展示常见. (附件) <!DOCTYPE html> <html> <head> <meta ...

  8. ubuntu 16.04 kinetic 安装rosbridge

    sudo apt-get install ros-kinetic-rosbridge-server

  9. Python day8常用格式化format类2

    format常用格式化 tp1="i am {},age {},{}".format('LittlePage',18,'boy') tp2="i am {},age {} ...

  10. Lua中Table的学习

    --table 是 Lua 的一种数据结构,用来帮助我们创建不同的数据类型,如:数组.字典等 --Lua也是通过table来解决模块(module).包(package)和对象(Object)的. 例 ...