Call Interface cache data

mounted () {
        this.initBtnConfig()
    },
    watch: {},
    methods: {
        async getbBannerBtnConfig () {
            let res = null
            try {
                res = await bannerBtnConfig()
            } catch (e) {
            }
            if (res && res.data) {
                let data = res.data
                localStorage.setItem('ciip_banner_config', JSON.stringify(data))
                localStorage.setItem('ciip_banner_config_times', (new Date()).getTime())
                this.currBannerBtnConfig = data[this.routePath] || {}
            }
        },
        initBtnConfig () {
            let times = Number(localStorage.getItem('ciip_banner_config_times') || 0)
            let nTimes = (new Date()).getTime()
            if (nTimes > times + 1000 * 60 * 60 * 24 * this.cacheDataDay) this.getbBannerBtnConfig()
            else {
                let json = JSON.parse(localStorage.getItem('ciip_banner_config') || {})
                if (json) this.currBannerBtnConfig = json[this.routePath] || {}
            }
        }
    }

 

Guess you like

Origin www.cnblogs.com/taochengyong/p/11282893.html