vue.js - laravel中使用vue,gulp打包後報_vueRouter2.default is not a constructor
世界只因有你
世界只因有你 2017-05-16 16:47:05
0
2
892

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')
世界只因有你
世界只因有你

全部回覆(2)
刘奇

雷雷

仅有的幸福

樓主解決了嘛,我的也是這個問題

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!