2016-10-18 2 views
0

Я использую компоненты laravel 5.3 + inbuild VueJs.Как импортировать внешние компоненты в laravel 5.3 + VueJs Маршруты

Теперь я хочу использовать маршруты, поэтому я использовал ниже код, который не работает.

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 вместо Page1

Я попытался 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') } 

    ] 
}) 
Смежные вопросы