0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Vuetify3 beta で Could not find injected Vuetify layout エラーが表示される

Posted at

(以前社内ブログに投稿していた記事の再掲です)

Vuetify3 betaで500:Could not find injected Vuetify layoutエラーが表示される原因と対策についてと、タグについてまとめました。

エラー内容

公式のコンポーネントのサンプルコードを実行したところ、以下画像のようにCould not find injected Vuetify layoutエラーが発生しました。

image.png

原因は、公式ページに記載されているサンプルコードがで囲われていないからです。

以下のように書くと、上記のエラーが発生しますが、

sample.vue
<template>
  <div>
    <v-app-bar>
      <v-app-bar-title>test</v-app-bar-title>
    </v-app-bar>
  </div>
</template>

以下のように書けばエラーは発生せずにAppBarは表示されます。

sample.vue
<template>
  <v-app>
    <v-app-bar>
      <v-app-bar-title>test</v-app-bar-title>
    </v-app-bar>
  </v-app>
</template>

について

そもそもタグとは、

と同様の役目を果たすVuetifyを利用する上で必須とされるタグです。

Vuetifyのコンポーネントタグはすべてタグの内側に記載する必要があります。

で囲わなくてもエラー無く表示されるコンポーネントもありますが、予期せぬ動作を招く原因になるので以下のように囲うようにしましょう。

sample.vue
<template>
  <v-app>
    // Vuetifyコンポーネントの記述
  </v-app>
</template>

参考

https://vuetifyjs.com/ja/components/application/

https://dev83.com/vue-vuetify-basic/

0
0
0

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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?