Created
July 16, 2019 18:34
-
-
Save renalpha/863331ca8f90b49980b07906fe4a38ba to your computer and use it in GitHub Desktop.
Vuejs with routing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * First we will load all of this project's JavaScript dependencies which | |
| * includes Vue and other libraries. It is a great starting point when | |
| * building robust, powerful web applications using Vue and Laravel. | |
| */ | |
| require('../js/loadScripts.js'); | |
| import Vue from 'vue'; | |
| import VueRouter from 'vue-router'; | |
| Vue.use(VueRouter); | |
| window.EventBus = new Vue(); | |
| const _ = require('lodash'); | |
| /** | |
| * Next, we will create a fresh Vue application instance and attach it to | |
| * the page. Then, you may begin adding components to this application | |
| * or customize the JavaScript scaffolding to fit your unique needs. | |
| */ | |
| Vue.prototype.trans = string => _.get(window.i18n, string); | |
| const router = new VueRouter({routes: require('./components/routes/web')}); | |
| const files = require.context('./', true, /\.vue$/i); | |
| files.keys().map(key => Vue.component(key.split('/').pop().split('.')[0], files(key).default)); | |
| const app = new Vue({ | |
| mode: 'history', | |
| router | |
| }).$mount('#app'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module.exports = [ | |
| { | |
| path: '/', | |
| component: require('../routes/ExampleComponent').default, | |
| name: 'home' | |
| }, | |
| { | |
| path: '/user', | |
| component: require('../routes/User').default, | |
| name: 'user' | |
| } | |
| ]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment