如何在laravel 5.3 + VueJs路由中导入外部组件
How to import external components in laravel 5.3 + VueJs Routes
我正在使用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')
,但它不工作,请帮助。
尝试使用vue-router。
const router = new VueRouter({
mode: 'hash',
base: __dirname,
routes: [
{ path: '/example',name: 'example', component: require('./example/example.vue') }
]
})
相关文章:
- 如何使用url加载程序在webpack中导入多个图像
- Emberjs应用程序加载在除Index之外的所有路由上
- 正在使用$location.path(.)路由ng视图
- 在AngularJS应用程序中使用封装指令和路由的推荐方式是什么
- 如何将JSON数据导入我的ejs模板
- 如何将不可变的js导入angular 2(alpha)
- 将数据从javascript文件导入VB.Net页面
- 导入jQuery脚本获胜'我不处理html文件
- 未激发路由的控制器属性上的观察者
- AngularJS ui路由器html5模式中断路由
- javascript导入的最佳实践是什么
- 发送json对象或使用express路由呈现视图
- 将CSV文件从URL导入Node.js
- 使用主干网和rails的静态页面路由
- Typescript导入导出的类会发出require(..),从而导致浏览器错误
- 如何将csv数据导入netsuite
- Angular 2-是否可以将我的路由存储在另一个文件中,并将它们导入到app.ts文件中(因为随着时间的推移,路由会不
- 将供应商JS文件导入Ember-CLI路由文件
- 如何在laravel 5.3 + VueJs路由中导入外部组件
- 确保导入的JavaScript文件在切换路由后仍能正常工作