• vue keep-alive


    //父页面
    <keep-alive>
        <router-view v-if="$route.meta&&$route.meta.keepalive"></router-view>
    </keep-alive>
        <router-view v-if="!($route.meta&&$route.meta.keepalive)"></router-view>
    

      

    //router
    router 添加meta属性和标识符
    {
           path:'list',
           component: () => import('./views/staff/total_list.vue'),
           meta:{
                          keepalive:true
                      }
     }
    

      

    //组件记录滚动条位置
    
    //mounted 挂载时添加滚动事件
      this.container=document.getElementById('container');
      this.container.addEventListener('scroll', this.handleScroll);
    
    //methods
    handleScroll(){
    this.scroll  =  this.container.scrollTop;
    }
    
    //activated 激活时赋值滚动条位置
    
     activated() {
                this.container=document.getElementById('container');
                if (this.scroll > 0) {
                    this.container.scrollTo(0, this.scroll);
                    this.scroll = 0;
                   this.container.addEventListener('scroll', this.handleScroll);
                }
            }
    //deactivated 非激活状态时 解绑滚动事件
      deactivated(){
                this.container.removeEventListener('scroll', this.handleScroll);
            }
    

      

  • 相关阅读:
    5.14事务
    5.13Mysql数据库Database
    未来打算
    浅谈P NP NPC
    1222
    1219
    Linux初等命令
    惩罚因子(penalty term)与损失函数(loss function)
    12 14
    java 泛型思考
  • 原文地址:https://www.cnblogs.com/yihuite-zch/p/10766675.html
Copyright © 2020-2023  润新知