1.index.js 配置子路由children。
import Vue from 'vue' import Router from 'vue-router' import SingerDetail from 'components/singer-detail/singer-detail'
Vue.use(Router)
export default new Router({ routes: [ { path: '/', redirect: '/recommend' }, { path: '/singer', component: Singer, //配置子路由,加一个参数children children: [ { //:id 以id为变量,传递一个参数,跳转到不同子路由 path: ':id', component: SingerDetail } ] }, { path: '/search', component: Search, children: [ { path: ':id', component: SingerDetail } ] } ] })
1.Singer
<template> <div class='singer'> <list-view @select='selectSinger'></list-view> //需要用routeview承载子路由 <router-view></router-view> </div> </template>
<script> import listView from '../components/listview' export default{ methods:{ selectSinger(singer){ //vue编程式跳转接口push this.$router.push({ path:'/singer/'+singer.id }) } }, components:{ listView } } </script>
<style> .singer{ } </style>
2.listview (singer子组件)
<template> <div class='listview'> <ul> <li @click='selectItem(item)'></li> </ul> </div> </template>
<script> export default{ methods:{ //内部把点击事件派发出去,告诉外部我被点击 selectItem(item){ this.$emit('select',item); } } } </script>
<style> .listview{ } </style>
3.singerDetail
<template> <transition name='slide'> <div class='singer-detail'></div> </transition> </template>
<script> </script>
<style> .singer-detail{ position:fixed z-index:100 top:0 left:0 right:0 bottom:0 background:lightgray } .slider-enter-active,.slider-leave-active{ transition: all 0.3s } .slider-enter,.slider-leave-to{ transform: translate3d(100%,0,0) } </style>
4.push转场动画
<transition name="slide"> <div class="chatdiv"> <div class="back" @click="backAction"></div> <div class="cont">免费咨询专业医生在线解答</div> </div> </transition>
<style> .slide-enter-active,.slide-leave-active{ transition: all 0.3s; } .slide-enter,.slide-leave-to{ transform: translate3d(100%,0,0); } </style>
以上这篇vue实现跳转接口push 转场动画示例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持亿速云。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。