Vue js;Vue router is not constructor error in simple route

谁说我不能喝 提交于 2019-12-04 05:30:00

This answer is for any onlookers hoping for a little more insight into the problem.

There are two solutions here.

Solution 1: ES Module Import

In Laravel's default config [at least], vue-router is expected to be imported as an es module. So, it should be done at the top of the file.

import VueRouter from 'vue-router'

Solution 2: CommonJS Require

Since vue-router router is an es module, you will have to explicitly access the default property of the CommonJS version of the module.

const VueRouter = require('vue-router').default;

Either Solution

You will have to register Vue Router with Vue.

Vue.use(VueRouter)

Based on the comments finally i resolved with this import

import VueRouter from 'vue-router';
Vue.use(VueRouter);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!