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.

いなたつAdvent Calendar 2019

Day 4

Vue.jsでちょっとおしゃんてぃなimport

Last updated at Posted at 2019-12-04

はじめに

いなたつアドカレの四日目の記事です。

今回はVue.jsで使えるちょっとかっこつけたおしゃんてぃなimport方法について書いてくぜ

じっそー

router.js
const loadView = view => () => import(`./views/${view}.vue`)

export default new Router({
  
  mode: 'history',
  base: process.env.BASE_URL,
  routes: [
    {
      path: '/',
      name: 'home',
      component: loadView('Home')
    },
    {
      path: '/about',
      name: 'about',
      component: loadView('About')
    }
  ]
})

こんなかんじですね、前提として、viewに関するファイルがviewsディレクトリにまとまっているとおもってください。

loadViewで引数viewを受けて無名関数を高階的にimportする関数を返却しています。
これで、import文を別に何度も書く必要がなく、importすることができ、すこしおしゃんてぃな感じが醸し出せます。

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?