解决vue报错Failed to mount component

[Vue warn]: Failed to mount component: template or render function not defined.
今天上班运行vue项目,当我进入昨天写的一个页面时,突然蹦出了上面这个错误,顿时我不知所挫了,昨天还好好的,为什么今天就报错了呢?


报错页面目录结构:

senior-certification(文件夹)
    errorMsg.js(表单验证提示文字)
    index.js(页面js,由于不想让index.vue文件代码数量过多,因此将script内容单独拿出来放到单独的js中)
    index.vue(页面)
    senior-certification.scoped.styl(样式)
    validations.js(表单验证器规则)

页面结构

<template>
    <div class="senior-certification-com">...</div>
</template>

<script>
    import index from './index.js';
    export default index;
</script>

<style lang="stylus" scoped>
    @import "senior-certification.scoped.styl"
</style>

router.js

let SeniorCertification = () => import('./views/usercenter/senior-certification');

const router = new Router({
    {
      path: '/usercenter/senior-certification',
      name: 'senior-certification',
      component: SeniorCertification,
      meta: { requireAuth: true },
    },
});
export default router;

以上代码看上去没有任何问题对吧,也看不出哪里有问题,毕竟昨天都还好好的。那么问题究竟出在哪呢?经过我反复测试及google,发现问题出现在这段代码中:
let SeniorCertification = () => import('./views/usercenter/senior-certification');
然后再看我的目录结构:

senior-certification(文件夹)
    errorMsg.js(表单验证提示文字)
    index.js(页面js,由于不想让index.vue文件代码数量过多,因此将script内容单独拿出来放到单独的js中)
    index.vue(页面)
    senior-certification.scoped.styl(样式)
    validations.js(表单验证器规则)

我把本应在<script>标签中的代码拿出来放到了index.js上,而我在router.js中引入组件时又偷懒了。因此vue-loader在引入时把index.js当做了入口,而不是index.vue。所以就出现了上面这个问题,解决方案很简单,引入组件时加个index.vue就可以了。
let SeniorCertification = () => import('./views/usercenter/senior-certification/index.vue');

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值