javascript - vue-router:无法解析异步组件默认值:SyntaxError: Unexpected token <
问题描述
在尝试使用 Vue 路由器导入 Vue 组件时,我不断收到此错误。
这是我的main_app.js
:
const Foo = { template: '<div>foo</div>' }
const Bar = { template: '<div>bar</div>' }
const Home = { template: '<div>Home</div>' }
const routes = [
{ path: '/foo', component: Foo },
{ path: '/bar', component: Bar },
{
path: '/home',
component: () => import('./list.vue')
}
]
const router = new VueRouter({
routes,
// mode: 'history'
})
const app = new Vue({
router
}).$mount('#app')
这是我的list.vue
:
<template>
<div id="right"></div>
</template>
<script>
export default {
name: 'list',
data: function () {
return {
text: 'some-text'
}
}
}
</script>
尝试进行此更改,但它不起作用,我恢复了。
const router = new VueRouter({
routes, // short for `routes: routes`
// mode: 'history'
output: {
path: '/js',
filename: '[name].js',
chunkFilename: 'js/[id].[chunkhash].js',
publicPath: '/',
},
})
谢谢你。
解决方案
现在,我尝试了这个并且它有效。不确定这是否是完美的解决方案。
我把代码改成了这个。
list.vue
export default {
name: 'list',
data: function () {
return {
text: 'some-text'
}
},
template: '<template> <div id="right"></div> </template>',
}
推荐阅读
- html - 如何使 n 数量的图像出现在 HTML 中的随机位置?
- javascript - 存储在 AsyncStorage 中的对象中的值不递增
- ruby-on-rails - Rails PG Search 返回的结果少于预期
- javascript - 此函数未返回预期代码
- azure - .NET 核心数据保护密钥不会自动更新
- javascript - UL 上的侦听器遍历 li
- python - 在 pandas 数据框中为序数创建虚拟变量
- python - 为什么python代码不应超过80个字符?
- scala - kuduContext.tableExists false?还是真的?
- mongodb - Sprint Boot Mongo Respositry 挂起第二个请求