Complete the code to access an environment variable in a Vue component.
const apiUrl = process.env.[1];In Vue, environment variables must start with VUE_APP_ to be accessible in the app code.
Complete the code to define a new environment variable in the .env file.
[1]=https://api.example.comEnvironment variables in Vue must be prefixed with VUE_APP_ in the .env file to be loaded.
Fix the error in accessing the environment variable inside a Vue component.
console.log(import.meta.env.[1]);
In Vue 3 with Vite, environment variables use the VITE_ prefix and are accessed via import.meta.env.
Fill both blanks to create a computed property that returns the API URL from environment variables.
import { computed } from 'vue'; const apiUrl = computed(() => [1].env.[2]);
In Vue 3 with Vite, environment variables are accessed via import.meta.env and use the VITE_ prefix.
Fill all three blanks to create a method that logs the environment variable and handles missing values.
methods: {
logApiUrl() {
const url = [1].env.[2] || [3];
console.log(url);
}
}This method uses import.meta.env.VITE_API_URL to get the URL and provides a fallback string if it's missing.