zoukankan      html  css  js  c++  java
  • 在Vue退出组件前,将不为空的参数保存到本地

        // 退出页面前将data中不为空的值到存到sessionstorage中,在进入页面时判断本地是否有当前页面name,有则赋值无则正常刷新
        //   存store也可
        beforeRouteLeave(to, form, next) {
            console.log(this)
            let a = [],
                b = {}
            let reg = /^(?![\$,_,__,rowStyle]).*/
            for (var key in this) {
                if (
                    typeof this[key] !== 'function' &&
                    this[key] !== '' &&
                    reg.test(key)
                ) {
                    if (Array.isArray(this[key]) && this[key].length == 0) {
                
                    } else {
                        b[key] = this[key]
                    }
                } else {
          
                }
            }
            sessionStorage.setItem(this.$options.name, JSON.stringify(b))
    
            next()
        },
    
    
    
        mounted: function() {
            if (sessionStorage.getItem(this.$options.name)) {
                console.log(JSON.parse(sessionStorage.getItem(this.$options.name)))
                let a = JSON.parse(sessionStorage.getItem(this.$options.name))
                for (var key in a) {
                    this[key] = a[key]
                }
                sessionStorage.removeItem(this.$options.name);
    
            } else {
                this.auditType = 1
                this.enterTableQuery()
            }
    
        },
    
  • 相关阅读:
    第二次作业。。
    第一次随笔作业
    第一次作业
    第4次随笔
    第3次随笔
    第2次作业
    第一次随笔
    我的第一次随笔
    iforums
    第四次作业
  • 原文地址:https://www.cnblogs.com/dudududadada/p/15555955.html
Copyright © 2011-2022 走看看