SoFunction
Updated on 2025-03-04

The difference between vue path writing about ./ and @/

About the difference between ./ and @/

When referring to the path, vue can be quoted using the ./ method as follows:

import './api/index'

This means the absolute path under the same file. There are also common usages of @ in the project:

import util from '@/assets/js/util'

This @ is configured in the file. Find the following paragraph

  resolve: {
    extensions: ['.js', '.vue', '.json'],
    alias: {
      'vue$': 'vue/dist/victory',
      '@': resolve('src'),
    }
  },

The @ here means src, so you can find the file under the src path, and you can configure it yourself. This is also a common way to write the path!

Replace the path ./ with @ in the vue project

We just need to add a file and some configuration in the project root directory

{
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "@/*": ["./src/*"],
    }
  },
  "exclude": ["node_modules", "dist"]
}

The above is personal experience. I hope you can give you a reference and I hope you can support me more.