I recently developed a plugin that is supposed to send data to my backend. However, I encountered an issue while setting up the backend URL configuration. When I checked the URL using "console.log(...)" in my code (in sendDataToBackEnd.js), I received an output of "undefined". The error message displayed was: "Error message: Cannot read property 'backEndUrl' of null"
Here is the project structure:
project1
public
backend-config.js
faviocon.ico
index.html
src
App.vue
main.js
config
backEndUrlConfig.js
plugin
sendDataToBackEnd.js
To resolve this issue, I created backend-config.js within the "public" folder:
(function (window) {
window._backendconfig = {
urlBackend: `http://localhost:8090/api/auth/event`,
}
}(this));
My config.js file looks like this:
export default { ...window._backendconfig }
And here is the code for my plugin "sendDataToBackEnd.js":
import url from '../../config/backendURLconfig';
var backEndUrl = url.urlBackend;
console.log(backEndUrl)
const sendDatatoBackEnd = {}
sendDataToBackEnd.install = function (Vue){
{Method to send Data to my Backend}
}
export default sendDatatoBackEnd;