[Vuejs]-How to access a variable defined in application.properties from vuejs?

2👍

When you use vue.js, you are using a client-side executed framework (as opposed to Thymeleaf, which is a server-side executed framework). That is, vue.js has no access to the information available in the backend without further ado.

Since the code contained in worker.js is executed in the client, you basically have only three ways to access the property:

  1. if the worker.js file is included in the Spring Boot project, you could replace a placeholder added to the worker.js with the value from the application.properties during the build process. However, this is probably not the intended goal, as you can then only set the value before running the build process.

  2. you create a resource in the backend when you start the service, which will be loaded by the vue.js application when it runs itself. This resource then contains the property with key and value so that the code contained in worker.js can determine the value for the matching key.

  3. you provide an endpoint in the backend so that the code contained in worker.js can access this endpoint during execution and query the value.

Only you can answer which solution is right for you.

Leave a comment