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 3 years have passed since last update.

初心者必見!!再利用するコンポーネントは「Vue.component」で定義しよう!

Posted at

皆さんこんにちは!

何回も使うコンポーネントって毎回importするの面倒くさくないですか??

それにimportした後にcomponentsで定義しなきゃいけない。。。

僕の場合、ユーザーに分かりやすいようにパンくずリストのコンポーネントをページごとに必ず設置します。

このように何回も使うコンポーネントは再利用できるようにVue.componentで定義しちゃいましょう!!

main.js
import Vue from 'vue'
// パンくずリストコンポーネント
import Breadcrumb from './components/Breadcrumb'

Vue.component('Breadcrumb', Breadcrumb)

一応簡単に説明しますね。

Vue.componentは、第1引数に呼び出すときの名前、第2引数に対象のコンポーネントをそれぞれ引数にします。

作業はこれだけです!

後はいつものように呼び出してあげてください。

作業効率アップ♪

以上、「初心者必見!!再利用するコンポーネントは「Vue.component」で定義しよう!」でした!

また、何か間違っていることがあればご指摘頂けると幸いです。

他にも初心者さん向けに記事を投稿しているので、時間があれば他の記事も見て下さい!!

あと、最近「ココナラ」で環境構築のお手伝いをするサービスを始めました。

気になる方はぜひ一度ご相談ください!

Thank you for reading

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?