LoginSignup
0
0

More than 1 year has passed since last update.

Vue.js 2 基底コンポーネントを一括登録する

Posted at

コード

// main.jsにて
// 基底コンポーネントフォルダパス: src/components/base
const files = require.context('./components/base, true', /\.vue$/)
const components = {}
files.keys().forEach(key => {
  components[key.replace(/(\.\/|\.vue)/g, '')] = files(key).default
})

Object.keys(components).forEach(key => {
  Vue.component(key, components[key])
})

使用

// コンポーネント内でそのまま使えば大丈夫です!
<base-title />
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