Vue JS Syntax error: "Unexpected Token, expected ,
Vue JS Syntax error: "Unexpected Token, expected ,
我正在开发一个包含 VueJS 的 Django 应用程序。我是 Django 的新手,甚至是 VueJS 的新手。
当我尝试 运行 我的代码时出现此错误:
ERROR Failed to compile with 1 errors
2:11:51 PM
error in ./src/router/index.js
Syntax Error: Unexpected token, expected , (51:0)
49 | } 50 |
51 | })
| ^ 52 | 53 | export default router 54 |
@ ./src/main.js 5:0-30 @多
(webpack)-dev-server/client?http://localhost:8080
webpack/hot/dev-server./src/main.js
这是我的 router/index.js 文件内容:
import Vue from 'vue'
import Router from 'vue-router'
import Chat from '@/components/Chat'
import UserAuth from '@/components/UserAuth'
Vue.use(Router)
const router = new Router({
routes: [
{
path: '/chats',
name: 'Chat',
component: Chat
},
{
path: '/auth',
name: 'UserAuth',
component: UserAuth
}
]
})
router.beforeEach((to, from, next) => {
if (sessionStorage.getItem('authToken') !== null || to.path === '/auth') {
next()
}
else {
next('/auth')
}
}
})
export default router
语法错误的原因是什么,我该如何纠正?
检查您在以下位置的额外括号:
router.beforeEach((to, from, next) => {
if (sessionStorage.getItem('authToken') !== null || to.path === '/auth') {
next()
}
else {
next('/auth')
}
} <-----------
})
请删除它,一个提示使用代码编辑器,它们中的大多数会指出您可能没有意识到的这种愚蠢的错误。
我正在开发一个包含 VueJS 的 Django 应用程序。我是 Django 的新手,甚至是 VueJS 的新手。
当我尝试 运行 我的代码时出现此错误:
ERROR Failed to compile with 1 errors
2:11:51 PMerror in ./src/router/index.js
Syntax Error: Unexpected token, expected , (51:0)
49 | } 50 |
51 | }) | ^ 52 | 53 | export default router 54 |
@ ./src/main.js 5:0-30 @多 (webpack)-dev-server/client?http://localhost:8080 webpack/hot/dev-server./src/main.js
这是我的 router/index.js 文件内容:
import Vue from 'vue'
import Router from 'vue-router'
import Chat from '@/components/Chat'
import UserAuth from '@/components/UserAuth'
Vue.use(Router)
const router = new Router({
routes: [
{
path: '/chats',
name: 'Chat',
component: Chat
},
{
path: '/auth',
name: 'UserAuth',
component: UserAuth
}
]
})
router.beforeEach((to, from, next) => {
if (sessionStorage.getItem('authToken') !== null || to.path === '/auth') {
next()
}
else {
next('/auth')
}
}
})
export default router
语法错误的原因是什么,我该如何纠正?
检查您在以下位置的额外括号:
router.beforeEach((to, from, next) => {
if (sessionStorage.getItem('authToken') !== null || to.path === '/auth') {
next()
}
else {
next('/auth')
}
} <-----------
})
请删除它,一个提示使用代码编辑器,它们中的大多数会指出您可能没有意识到的这种愚蠢的错误。