LoginSignup
2

More than 3 years have passed since last update.

[Vue.js]Phpstorm 絶対パスでcomponentのパスを指定

Last updated at Posted at 2019-05-21

やりたいこと

絶対パスでcomponentのパスを指定する。
プログラムのエラーは出ないが、エディタ(私が使用しているものはPhpstormです)で
「文法違いますよ」というエラー(黄色の破線)が出る。
紛らわしいので、なんとかしたい。

修正前

<script>
// @ is an alias to /src

import TheClientHeader from '../../components/object/project/TheClientHeader' //←★修正前コレ
export default {
  name: 'Home',
  components: { TheClientFooter },
}
</script>

修正後

<script>
// @ is an alias to /src

import TheClientHeader from '@/components/object/project/TheClientHeader' //←★修正後コレ(文法エラーの表記は出ていない)
export default {
  name: 'Home',
  components: { TheClientFooter },
}
</script>

解決方法

import-resolver.jsというファイルをドキュメントルート直下に作成し、
以下を記述

/* eslint-disable no-undef */
System.config({
  paths: {
    '@/*': 'src/*',
  },
})

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2