在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML/ 通過localStorage 獲取到的數(shù)據(jù) 如何渲染到頁面上

通過localStorage 獲取到的數(shù)據(jù) 如何渲染到頁面上

在A頁面輸入內(nèi)容提交后提交到B頁面
需要實(shí)現(xiàn)B頁面刷新后,頁面內(nèi)容不丟失
目前已經(jīng)從localStorage中拿到數(shù)據(jù)并打印出來了 ,現(xiàn)在的問題是 如何把數(shù)據(jù)渲染到B頁面上。
以下是store.js 中的內(nèi)容

Vue.use(Vuex)
export default new Vuex.Store({
    state: {
        form: {
            name: '',
            content: '',
            src: ''
        },
        isWhite: false
    },
    mutations: {
        form(state, data) {
            data.src && RGBaster.colors(data.src, {
                success: function (payload) {
                    Object.assign(state.form, data)
                    const c = payload.dominant.match(/\d+/g);
                    let fontColor;
                    const grayLevel = c[0] * 0.299 + c[1] * 0.587 + c[2] * 0.114;
                    state.isWhite = grayLevel < 192
                    localStorage.setItem('cet', JSON.stringify(state))
                }
            });
            
        }
    }
})  

main.js中的內(nèi)容

import Vue from 'vue'
import App from './App'
import router from './router'
import store from './store'
import axios from './http'
import wx from 'weixin-js-sdk'
import 'weui'

Vue.config.productionTip = false

try {
    let info = JSON.parse(window.localStorage.getItem('cet') || null)
    if (info == '') {
        console.log('無數(shù)據(jù)')

    } else {
        console.log(info.form)
        this.$store.commit("form", data);
    }
} catch(err) {}
回答
編輯回答
蟲児飛

使用 Getter

嘗試從state取數(shù)據(jù),取不到再到localStorage里取

2017年9月8日 21:49