【问题标题】:What do I get an error when I attempt to connect a vue component to my router.js file?当我尝试将 vue 组件连接到我的 router.js 文件时,会出现什么错误?
【发布时间】:2017-10-26 17:46:12
【问题描述】:

我已经创建了我的 auth0 配置,现在我正在导入我的登录页面

import Vue from 'vue'
import Router from 'vue-router'


Vue.use(Router)


// create import statements
import login from './containers/login'
import home from './containers/home'
import dashboard from './containers/dashboard'
import projects from './containers/projects'
import auth from './auth'


// application routes

const routes = [

// each path will render each component when it experiences an event

{ path: '/', component: home },
{ path: '/dashboard', component: dashboard },
{ path: '/projects', component: projects }

]


// export router instance

/* Using mode : 'history '
This removes the hash from the url and gives
the app a cleaner url string
*/


export default new Router({
  mode: 'history',
  routes,

/* use link activeClass to indicate what
class to add to the navigation to make the menu item active

*/


  linkActiveClass: 'is-active'
})

我遇到了这个错误

Syntax Error: import is a reserved word (32:2)

在添加 login.vue 和 auth.js 之前,代码是可以运行的,但是当我输入它们时,它会返回上述错误。

我正在使用 vue.js 框架,并使用 Auth0 来保证安全性。

【问题讨论】:

  • 不使用的时候为什么要导入auth.js?

标签: vue.js vuejs2 auth0


【解决方案1】:

Import 是 ES2016 中的一个关键字,它是一个新的 JavaScript 标准。在我看来,您使用的是 ES5,这是目前大多数浏览器中可用的版本。要使用 ES6 功能,您需要使用 Babel 等工具将代码转换为 ES5。如果你按照教程使用 vue-cli 创建项目,Babel 应该会自动配置到你的项目中。

【讨论】:

    猜你喜欢
    • 2022-06-13
    • 1970-01-01
    • 2021-05-28
    • 2012-06-14
    • 1970-01-01
    • 2011-07-12
    • 2011-06-02
    • 2021-09-27
    • 2020-03-19
    相关资源
    最近更新 更多