I have a list of fruits saved in a file named fruit_list
. The file contains the following information.
export default {
fruits: [
'APPLE',
'BANANA',
'CHERRY',
'GRAPE',
'KIWI',
'MANGO',
'ORANGE',
'PEAR',
'PINEAPPLE',
'STRAWBERRY',
'WATERMELON'
]
}
In the index.js
file, I imported this list and assigned it to a variable:
import fruitList from './config/fruit_list';
Vue.prototype['$fruitData'] = fruitList;
Now I am attempting to access this variable $fruits
in a script called operations.js
using the following code:
export const checkFruitIncluded = (fruit) => {
const fruits = this.$fruitData.fruits;
return fruits.includes(fruit);
}
This function checkFruitIncluded
is then invoked from a functionality.
However, I encountered an error stating
Uncaught TypeError: Cannot read property 'fruits' of undefined
As a beginner with VueJS, any help in identifying what's lacking here would be appreciated.