router ⇒ view ⇒ router の循環依存に対する対処法 #2432
Unanswered
KentaHizume
asked this question in
05: Q&A
Replies: 1 comment
-
対処法import/no-cycle に対してオプション
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
問題
import/no-cycle
View.vue ──► import { router } from '@/router' router/index ──► import View from '@/views/View.vue'次のような実装はESLintによって警告されるが、動作する。
この文章の作成中に急にESLintの警告が出力されなくなり迷宮入り
View内でrouterをimport
しかし実際には、下記のようにViewのimportはlazy loadingされているので、
(1)view は定義時点でrouterを静的にローディングし、viewが評価される(固まる)
(2)routerは定義時点で view のモジュール本体を読み込まず、後からViewを読み込む
という順序で処理されるので、実行時の依存関係は一方向になり、問題なく動作する。
inject() can only be used inside setup() or functional components.
一方で次のような実装はVueによって実行時に警告が出力され、動作しない。
このケースにおいては、上記のようにrouterを直接importする必要がある
Beta Was this translation helpful? Give feedback.
All reactions