problem: weex introduced vuex and got stuck on this
2018-12-11 14:59:54.696233+0800 XYT[13100:4041493] <Weex>[log]WXJSCoreBridge.m:145, jsLog: 111
2018-12-11 14:59:54.699016+0800 XYT[13100:4041493] <Weex>[log]WXJSCoreBridge.m:145, jsLog: store.state.count: 1
2018-12-11 14:59:54.707954+0800 XYT[13100:4041493] <Weex>[error]WXMonitor.m:221, [native-bundle-main.js:1:29760] TypeError: JSON.stringify cannot serialize cyclic structures.
stringify@[native code]
weex-v:
~ weex -v
v1.3.11
- weexpack : v1.2.7
- weex-builder : v0.4.0
- weex-previewer : v1.5.1
implement logic:
premise: do not use vue-loader
modify webpack.common.conf.js
const relativeStorePath = path.join(relativeVuePath, "../store/index.js")
if (relativeVuePath.indexOf("index") > -1) {
contents += `import App from "${relativeVuePath}"
import store from "${relativeStorePath}"
new Vue(Vue.util.extend({el: "-sharproot", store}, App));
`;
}
the result obtained is that the .temp file is generated under the weex project as follows
import App from "../src/index.vue"
import store from "../src/store/index.js"
new Vue(Vue.util.extend({el: "-sharproot", store}, App));
store file:
import Vuex from "vuex"
console.log(111)
// Vuex is auto installed on the web
if (WXEnvironment.platform !== "Web") {
Vue.use(Vuex)
}
const store = new Vuex.Store({
state: {
count: 0
},
mutations: {
increment (state) {
state.countPP
}
}
})
store.commit("increment")
console.log("store.state.count: ", store.state.count) // -> 1
export default store