[Vuejs]-Proper way to import component vue js

0๐Ÿ‘

../ or just .. is shorthand for the directory above the current one. so you are searching for vue.config in src folder if you used it in Main_screen.vue and searching for the file in the parent of src when you use it in main.js. try importing it like this in Main_screen.vue:

import { api_url } from '../../vue.config'

On the other hand one dot . means the current directory which means if you import something like import { api_url } from './vue.config' inside main.js it will give you an error because you are searching for the file inside src folder

Edit

As Lawrence Cherone said in the comments:

import { api_url } from '../../../../../../vue.config' can happen quickly in a larger project, is better to do import { api_url } from '~/vue.config'. ~ being where package.json is.

Leave a comment