Answer the question
In order to leave comments, you need to log in
How to overcome the "Cannot access before initialization" error?
Good afternoon. I use webpack+babel+vue.
I have 2 files app.js and methods.js
app.js contains Vue object and constant with object.
import {VUE_METHODS} from 'methods';
export const NDS = {
title: 'НДС 20%'
};
VUE_METHODS.methods.objectFreeze(NDS);
export let app = new Vue({
el : '#app',
mixins : [VUE_METHODS],
//бла бла бла дальше не важно
});
import axios from 'axios';
import {NDS} from 'app';
export const VUE_METHODS = {
data : function () {
return {
nds: NDS
}
},
computed: {
//бла бла бла
},
methods : {
objectFreeze : function (_o, _property = null) {
//не важно
}
}
};
import 'methods';
import 'app';
Uncaught ReferenceError: Cannot access 'ne' before initialization
VUE_METHODS.methods.objectFreeze(NDS);
Answer the question
In order to leave comments, you need to log in
You have a classic example of a cyclic dependency, move NDS into a separate module, otherwise you get the app -> methods -> app loading chain
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question