鍍金池/ 問答/網(wǎng)絡(luò)安全  HTML/ vue keepalive頁面未被緩存,每次進(jìn)入頁面都會(huì)調(diào)用mounted跟ac

vue keepalive頁面未被緩存,每次進(jìn)入頁面都會(huì)調(diào)用mounted跟activated鉤子

需求是每次進(jìn)入頁面比如content不會(huì)重新刷新,但是無論是切換路由還是前進(jìn)后退都會(huì)刷新頁面
路由配置:

mode:'history',
  routes: [
  {
      path: '/',
      redirect:'/content',
      component: home,
      children:[
  // 要是hash路由,這里無論點(diǎn)那個(gè)路由都是跳轉(zhuǎn)到content
  {path:'/about', name:'about', component:about,meta:{keepAlive:true}},
  {path:'/archives',name:'archives',component:archives,meta:{keepAlive:true}},
  {path:'/content',name:'content',component:content,meta:{keepAlive:true}},
  {path:'/article:_id',name:'article',component:article,meta:{keepAlive:true}}//這里的name是命名路由里面的參數(shù)name
  ]

},
根組件
<div id="app">

    <!-- 不管寫沒寫跟路由都在APP。vue里面?一定要加上這一句 -->
    <loading v-show="isloading"></loading>
        <router-view></router-view>
</div>

home組件

回答
編輯回答
枕邊人

你的設(shè)置組件的name 屬性,不是在路由里面設(shè)置,在組件里面設(shè)置才可以

2018年7月31日 09:11