在“ ./router”中找不到导出“默认”(导入为“路由器”)

时间:2019-12-12 20:38:41

标签: javascript html vue.js

嗨,我想在另一个文件中实现vue路由器,但出现一个错误:在“ ./router”中找不到“导出'默认'(导入为'路由器')

谢谢。

// Import
import Vue from 'vue'
import axios from 'axios'
import VueMeta from 'vue-meta'
import { router  }from './router'
import App from './pages/app'

// Config
Vue.use(VueMeta)
window.axios = axios
Vue.config.productionTip = false

// Start Vue.js
new Vue({
  router,
  ...App
})

router / index.js

import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const Bar = { template: '<div>bar</div>' }

let routes = [
    // Login
    { path: '/login', component: Bar },

    // Errors
    { path: '*',  component: Bar  }
]

const router = new VueRouter({
    base: 'public', 
    mode: 'history',
    routes
})

1 个答案:

答案 0 :(得分:2)

要从router文件中导入/index.js,您需要实际将其导出。只需在export文件中的const router =之前添加router/index.js。看起来像这样:

import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const Bar = { template: '<div>bar</div>' }

let routes = [
    // Login
    { path: '/login', component: Bar },

    // Errors
    { path: '*',  component: Bar  }
]

export const router = new VueRouter({
    base: 'public', 
    mode: 'history',
    routes
})