vue 使用 keep-alive 缓存页面

1、把需要缓存的组件 name 写在  include上

注:(如果使用动画写两个 transition 的话会出现动画混乱的问题)

            
                    
                        
                    
            

 

2、 keep-alive 里面有两个方法是,,缓存之后,页面进来和页面出去的方法,,不过滚动条的位置不会缓存,所以要记录一下最后的位置,,然后进来的时候自己再跳到记录点

//缓存页面再进来
    activated(){
        this.scrollTo();
        this.$refs.loadmoreBox.addEventListener('scroll', this.handleScroll);
    },
    //缓存页面离开
    deactivated(){
        this.$refs.loadmoreBox.removeEventListener('scroll', this.handleScroll);
    },

 

你可能感兴趣的:(vue)