2016-10-18 39 views
0

私はlaravel 5.3 + inbuild VueJs componetsを使用しています。laravel 5.3 + VueJsルートで外部コンポーネントをインポートする方法

ここではルートを使用したいので、以下のコードを使用していますが動作しません。 Page1

の代わりに

const NotFound = { template: '<p>Page not found</p>' } 
const Page1 = { template: '<p>home page</p>' } 
const Page2 = { template: '<p>about page</p>' } 
const routes = { 
    '/': Page1, 
    '/page2': Page2 
} 

const app = new Vue({ 
    el: '#app', 
    data: { 
     currentRoute: window.location.pathname 
    }, 
    computed: { 
     ViewComponent() { 
      return routes[this.currentRoute] || NotFound 
     } 
    }, 
    render (h) { return h(this.ViewComponent) } 
}); 

どのようにインポートExample.vue私はrequire('./components/Example.vue')を試してみましたが、そのは助けてください動作していません。

+0

'const Page1 = require( './ components/Example.vue')'を試したときのエラーは何ですか? – SimonDepelchin

+0

gulpがこのコードで実行されていないため、エラーはありません – Drone

+0

実行されていない場合はエラーをスローしますか? – SimonDepelchin

答えて

0

vue-routerを使用してみてください。

const router = new VueRouter({ 
    mode: 'hash', 
    base: __dirname, 
    routes: [ 
    { path: '/example',name: 'example', component: require('./example/example.vue') } 

    ] 
}) 
関連する問題