【问题标题】:Import custom vue component in main.js file在 main.js 文件中导入自定义 vue 组件
【发布时间】:2021-06-19 19:18:20
【问题描述】:

我有很多 Vue 组件。我想从 main.js 文件为它们设置路由。但我无法在此处导入我的组件,因为它是一个 javascript 文件。如何在此处导入我的 Vue 组件(.vue)?

import Vue from 'vue'
import App from './App.vue'

// Components importing
import LandingPage './components/LandingPage.vue'; // error occurs here

const routes = [
  { path: '/', component: LandingPage },
]

const router = new VueRouter({
  routes // short for `routes: routes`
})

Vue.config.productionTip = false

new Vue({
  render: h => h(App),
  router
}).$mount('#app')

【问题讨论】:

    标签: vue.js vuejs2 vue-component


    【解决方案1】:

    尝试导入喜欢 导入 { LandingPage } './components/LandingPage.vue'

    或者将导出默认设置为 LandingPage 组件。

    【讨论】:

      猜你喜欢
      • 2021-06-25
      • 1970-01-01
      • 2019-01-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-19
      • 2021-07-26
      • 2018-12-04
      相关资源
      最近更新 更多