I have a country list that is saved as a configuration file country_list. The file has the following contents.
export default {
countries: [
'AUSTRALIA',
'AUSTRIA',
'BELGIUM',
'BRAZIL',
'BULGARIA',
'CANADA',
'CHINA',
'CROATIA',
'CYPRUS',
'CZECHIA',
'DENMARK',
'ESTONIA',
'FINLAND'
]
}
Now in the main.js file I am importing it and set it as an instance variable
import countryList from './config/country_list';
Vue.prototype['$countryData'] = countryList;
Now I am trying to access this variable $countries in a file called utils.js like the following :
export const checkCountryIncluded = (country) => {
const countries = this.$countryData.countries;
return countries.includes(country);
}
and this checkCountryIncluded is called from a component.
But here I am getting an error Uncaught TypeError: Cannot read property 'countries' of undefined
I am new to VueJS and it will be helpful if someone can point out what is missing here.
import * as countryList? Otherwise you can also doexport const countries = [ ... ];thenimport { countries } from './config/country_list';const countries =...lineutils.jsfile. I need to importmain.jsfile here ?utils.jsfile which usesconst countries = this.$countryData.countrieswhen do you call it?