[Vuejs]-"ReferenceError: is not defined" accessing variable in javascript

0đź‘Ť

âś…

You exported val1090 as default, so when you call this

import validator from "./validator"

You declare a variable validator containing what’s exported by default in the validator file. Meaning that validator is the variable containing

    {
     'validators': [
        {
            'name': 'RangeValidator',
            'params': {
                'minimum': 10,
                'maximum': 90,
                'errorMessage': 'Value must be between 10-90.',
           }
        },
    ]
  }

So you should use validator instead of val1090 in your runesMetadata.js, or change your first line to

import val1090 from "./validator"

EDIT : If your validator has more objects, it works the same. The export default value will be contained in the variable you import it. so if you export this :

export default {
    val1090,
    val115
}

and import it like this :

import validator from "./validator"

You basically create a variable variable with this value :

validator = {
    val1090: val1090,
    val115: val115
}

And accessing the val1090 value can be done like this :

validator.val1090

0đź‘Ť

Having just a property name in a object initializer, i.e. just val1090 is new ES6+ “shorthand” for val1090:val1090 see MDN docs … for that to work, there MUST be a variable declared called val1090 … which isn’t the case in your code

e.g

var a = 'foo', b = 42, c = {};
var o = {a, b, c};

works, because a, b and c are declared variables

var a = 'foo', b = 42;
var o = {a, b, c};

fails, because c is not declared

Leave a comment