vue2.0 如何实现页面缓存

https://img1.mukewang.com/5c570c860001353703960585.jpg

数据请求,是通过点击上面的分类(所以分类共用一个数据请求页面),监控路由变化,只要路由变化就会请求数据,这样的话页面请求的数据就缓存不了

watch: {
    $route: function() {      // if (this.routerChange) {
        this.getNews()      // }
    }
  },
  methods: {
    ...mapActions(['getList', 'dowmLoadmore']),
    getFirstNews(){      this.getList({
        channel: this.firstName,
        type: this.firstType,
        flag: this.routerChange
      })
    },
    getNews() {      this.getList({
          channel: this.$route.query.type,
          type: this.$route.params.type,
          flag: this.routerChange
        })

keep-alive也开启了

{
      path: '/header',
      name: 'Header',
      component: Header,
      meta:{  keepAlive: false },
      children: [
        {
          path: '/home/:type',
          name: 'Home',
          component: Home,
          meta:{  keepAlive: true  }
        }
      ]
    },

现在还是只要切换分类,页面就会刷新,不知道该怎么改了


肥皂起泡泡
浏览 1281回答 0
0回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Vue.js