Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

NoLAstNamE's avatar

Vue imports

What's the difference between @ and ./ when importing Vue components?

Let's use Laravel Breeze scaffolding for example. All pages use @ for importing components.

AuthenticatedLayout.vue

<script setup>
import { ref } from 'vue';
import ApplicationLogo from '@/Components/ApplicationLogo.vue';
import Dropdown from '@/Components/Dropdown.vue';
import DropdownLink from '@/Components/DropdownLink.vue';
import NavLink from '@/Components/NavLink.vue';
import ResponsiveNavLink from '@/Components/ResponsiveNavLink.vue';
import { Link } from '@inertiajs/vue3';

const showingNavigationDropdown = ref(false);
</script>

I'm confused because of my Code Editor (VSCode). When I'm typing a component, it suggests ./ and when I click it, it will import the component.

Like this

import Post from "./Pages/Post.vue"
0 likes
6 replies
LaryAI's avatar
Level 58

In Vue, @ is an alias for the src directory, which is the root directory for your project's source files. On the other hand, ./ is used to import a component relative to the current file.

So, when you use @ to import a component, you are importing it from the src directory, regardless of where the current file is located. This is useful when you have a deep directory structure and want to avoid long relative paths.

When you use ./ to import a component, you are importing it relative to the current file. This is useful when you want to import a component that is located in the same directory as the current file, or in a subdirectory.

In the example provided, the components are imported using @ because they are located in the src/Components directory. However, when you start typing a component name in VSCode, it suggests using ./ because it assumes that you want to import a component relative to the current file.

So, to summarize:

  • Use @ to import components from the src directory.
  • Use ./ to import components relative to the current file.

Code example:

// Importing a component using @
import MyComponent from '@/Components/MyComponent.vue';

// Importing a component using ./ (relative to the current file)
import MyComponent from './MyComponent.vue';
1 like
NoLAstNamE's avatar

But why do others prefer using just the @ instead of ./

ramonrietdijk's avatar
Level 30

@NoLAstNamE Because ./ is relative to the current directory. If you are working within a nested directory, climbing up the tree can be hard to read. Example:

<!-- File is located in "src/Pages/Nested/Home.vue" -->

<script setup>
import NavLink from '@/Components/NavLink.vue'; // Using the alias

import NavLink from '../../Components/NavLink.vue'; // Using the relative path
</script>
1 like

Please or to participate in this conversation.