In my main.js
file, I am initializing a new Vue instance on the window object:
window.todoEventBus = new Vue()
Within my components, I am attempting to access this global todoEventBus object like so:
created() {
todoEventBus.$on('pluralise', this.handlePluralise);
},
Unfortunately, I am encountering errors indicating:
Failed to compile.
./src/components/TodoItem.vue
Module Error (from ./node_modules/eslint-loader/index.js):
error: 'todoEventBus' is not defined (no-undef) at src\components\TodoItem.vue:57:9:
55 |
56 | created() {
> 57 | todoEventBus.$on('pluralise', this.handlePluralise);
| ^
58 | },
59 |
60 | methods: {
1 error found.
However, if I console.log todoEventBus, I can see the Vue object.
The content of my package.json file is as follows:
{
"name": "todo-vue",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint"
},
"dependencies": {
"core-js": "^3.3.2",
"vue": "^2.6.10"
},
"devDependencies": {
"@vue/cli-plugin-babel": "^4.0.0",
"@vue/cli-plugin-eslint": "^4.0.0",
"@vue/cli-service": "^4.0.0",
"babel-eslint": "^10.0.3",
"eslint": "^5.16.0",
"eslint-plugin-vue": "^5.0.0",
"sass": "^1.23.1",
"sass-loader": "^8.0.0",
"vue-template-compiler": "^2.6.10"
},
"eslintConfig": {
"root": true,
"env": {
"node": true
},
"extends": [
"plugin:vue/essential",
"eslint:recommended"
],
"rules": {},
"parserOptions": {
"parser": "babel-eslint"
}
},
"postcss": {
"plugins": {
"autoprefixer": {}
}
},
"browserslist": [
"> 1%",
"last 2 versions"
]
}