1.创建components/singer-detail/singer-detail.vue
2.配置动态路由:
1 { 2 path: ':id', 3 name:'singer-detail', 4 component:()=>import('@/components/singer-detail/singer-detail.vue') 5 }
3.在listview.vue中emitselectSinger事件来触发选择明星,并将选择的明星item作为参数派发给singer.vue
1 seletSinger(singerName){ 2 this.$emit('selectSinger',singerName) 3 },
4.singer中监听派发的selectsinger事件,并设置路由跳转;
1 selectSinger(singerName){ 2 this.$router.push({ 3 path: `/singer/${singerName.id}` 4 }) 5 },
5.给singer.vue中添加<router-view></router-view>来显示子组件singer-detail.vue的内容;因为会将父子组件一起显示,为了只显示子组件,给singer-detail.vue添加样式:
1 .singer-detail{ 2 position: fixed; 3 z-index: 100; 4 top: 0; 5 left: 0; 6 bottom: 0; 7 right: 0; 8 background: #222; 9 }
5.给在切换到歌手详情页的时候添加动画:在singer-detail.vue最外层包<transition></transition>并设置样式:
1 .slide-enter-active, .slide-leave-active { 2 transition: all 0.3s 3 4 } 5 .slide-enter, .slide-leave-to { 6 7 transform: translate3d(100%, 0, 0) 8 }