javascript - vue 2.0 router每次切换页面都会重载
ringa_lee
ringa_lee 2017-04-11 10:18:55
[JavaScript讨论组]

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)

ringa_lee
ringa_lee

ringa_lee

全部回复(2)
怪我咯

请使用keep-alive

PHP中文网

使用异步加载组件(懒加载),就不会有这问题了
https://router.vuejs.org/zh-c...

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号