如何在 laravel 5.3 + VueJs Routes 中导入外部组件
Posted
技术标签:
【中文标题】如何在 laravel 5.3 + VueJs Routes 中导入外部组件【英文标题】:How to import external components in laravel 5.3 + VueJs Routes 【发布时间】:2017-02-27 06:48:05 【问题描述】:我正在使用 laravel 5.3 + inbuild 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')
,但它不起作用,请帮忙。
【问题讨论】:
您尝试const Page1 = require('./components/Example.vue')
时出现什么错误?
没有错误,因为 gulp 没有使用此代码运行
如果它没有运行它会抛出一个错误,不是吗?
【参考方案1】:
尝试使用 vue-router。
const router = new VueRouter(
mode: 'hash',
base: __dirname,
routes: [
path: '/example',name: 'example', component: require('./example/example.vue')
]
)
【讨论】:
以上是关于如何在 laravel 5.3 + VueJs Routes 中导入外部组件的主要内容,如果未能解决你的问题,请参考以下文章
vuejs 组件未在我的 laravel 5.3 刀片页面中呈现
CSRF 令牌不匹配错误,Laravel 5.3/VueJS2
vue.js 2.0 在 laravel 5.3 中动态加载组件