Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
345 views
in Technique[技术] by (71.8m points)

laravel中使用vue,gulp打包后报_vueRouter2.default is not a constructor

gulp打包成功,但在页面报js错误:
在Chrome的console中的错误代码:

main.js?6e4b:26 Uncaught TypeError: _vueRouter2.default is not a constructor
    at Object.eval (eval at <anonymous> (main.js:128), <anonymous>:26:14)
    at eval (eval at <anonymous> (main.js:128), <anonymous>:33:30)
    at Object.<anonymous> (main.js:128)
    at __webpack_require__ (main.js:20)
    at main.js:64
    at main.js:67

package.json:

{
  "private": true,
  "devDependencies": {
    "gulp": "^3.8.8",
    "laravel-elixir": "^6.0.0-9",
    "laravel-elixir-browsersync-official": "^1.0.0",
    "laravel-elixir-vue": "^0.1.4",
    "laravel-elixir-webpack-official": "^1.0.2",
    "lodash": "^4.14.0",
    "node-sass" :"^4.0.0",
    "sass": "^0.5.0",
    "sass-loader": "^6.0.3",
    "vue": "^2.1.0",
    "vue-resource": "^1.0.1",
    "vue-router": "^2.1.1",
    "webpack": "^2.1.0"
  },
  "dependencies": {
    "bootstrap-sass": "^3.0.0"
  }
}

gulpfile.js:

var elixir = require('laravel-elixir');

require('laravel-elixir-vue');

elixir(mix => {
    mix.webpack('main.js');
});

main.js:

import Vue from 'vue/dist/vue.js'
import App from './App.vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter);

//开启debug模式
Vue.config.debug = true;

import Example from './components/Example.vue'

const router = new VueRouter({
    mode: 'history',
    base: __dirname,
    routes: [
        { path: '/example', component: Example }
    ]
})

new Vue(Vue.util.extend({ router }, App)).$mount('#app')

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
new Vue({
    router,
    render: (h) => h(App)
}).$mount('#app')

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...