在main.js里导入并使用vue-resource

// main.js  
  
// 导入Vue,这个是必需的,在使用Vue之前,必须先导入  
import Vue from 'vue'  
  
// 导入 vue-router,并使用  
import VueRouter from 'vue-router'  
Vue.use(VueRouter)  
  
// 导入 vue-resource,并使用  
import VueResource from 'vue-resource'  
Vue.use(VueResource)  
  
// 导入 pages 下的 Home.vue   
import Home from './pages/Home'  
import Detail from './pages/Detail'  
  
// 定义路由配置  
const routes = [  
    {  
        path: '/',  
        component: Home  
    },  
    {  
        path: '/detail',  
        component: Detail  
    }  
]  
  
// 创建路由实例  
const router = new VueRouter({  
    routes  
})  
  
// 创建 Vue 实例  
new Vue({  
  el: '#app',  
  data(){  
    return {  
        transitionName: 'slide'  
    }  
  },  
  router,  
  watch: {  
    // 监视路由,参数为要目标路由和当前页面的路由  
    '$route' (to, from){  
        const toDepth = to.path.substring(0, to.path.length-2).split('/').length  
        // 官方给出的例子为 const toDepth = to.path.split('/').length 由于现在只有两个路由路径'/'和'/detail'  
        // 按照官方给的例子,这两个路由路径深度都为 2 ,所以,这里稍作调整,不知道有什么不妥  
        // 但目前在这个demo中能正常运行,如果知道更好的方法,欢迎留言赐教  
        const fromDepth = from.path.substring(0, from.path.length-2).split('/').length  
        this.transitionName = toDepth < fromDepth ? 'slide_back' : 'slide'  
        // 根据路由深度,来判断是该从右侧进入还是该从左侧进入  
    }  
  }  
})  

转自https://blog.csdn.net/u013182762/article/details/53488870


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值