router/index.js
import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)
const route = new VueRouter({
routes:[
{
path:'/song/list',component: require('../views/song_list')
},{
path:'/singer/list',component: require('../views/singer_list')
},{
path:'/custom/list',component: require('../views/custom_list')
},{
path:'*',redirect:'/song/list'
}
]
})
export default route;
头部导航
this.$router.push({path:this.headTabs[index].path})
子页面每次都会重载(打印'song_list加载了')
created (){
console.log('song_list加载了')
this.reqSongList();
var mySwiper = new Swiper('.swiper-container', {
direction: 'horizontal',
loop: true,
autoplay : 3000,
pagination: '.swiper-pagination'
});
}
看别人的例子都是加载一次后,再次切换时都是直接显示了(没有加动态参数),没有重载(触发created)
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
请使用keep-alive
使用异步加载组件(懒加载),就不会有这问题了

https://router.vuejs.org/zh-c...