after the input content of page An is submitted to page B
, after page B needs to be refreshed, the page content will not be lost
. At present, the data has been obtained from localStorage and printed out. The problem now is how to render the data to page B.
the following is the content in store.js
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))
}
});
}
}
})
content in main.js
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("")
} else {
console.log(info.form)
this.$store.commit("form", data);
}
} catch(err) {}