vue-router

What is the best Vue-Router practice for very large webapplications?

ⅰ亾dé卋堺 提交于 2019-12-03 03:43:38
问题 I have to make a webapplication with many different modules (like a todo-module, document-modules, and a big usermanagement-module for admin users). The total number of pages is > 100. And the module access is different for each user. I am working with Laravel and Vue-router . But what is the best practice to do it? Create a SPA-application, with 1 large vue-router for everything? For every module a own single "SPA" (with and own vue-router)? Or another suggestion...? 回答1: Little late but I

How can I get query parameters from a URL in Vue.js?

寵の児 提交于 2019-12-03 03:13:42
问题 How can I fetch query parameters in Vue.js? E.g. http://somesite.com?test=yay . Can’t find a way to fetch or do I need to use pure JS or some library for this? 回答1: According to the docs of route object, you have access to a $route object from your components, that expose what you need. In this case //from your component console.log(this.$route.query.test) // outputs 'yay' 回答2: Without vue-route, split the URL var vm = new Vue({ .... created() { let uri = window.location.href.split('?'); if

How to VueJS router-link active style

隐身守侯 提交于 2019-12-03 02:59:27
问题 My page currently has Navigation.vue component. I want to make the each navigation hover and active. The 'hover' works but 'active' doesn't. This is how Navigation.vue file looks like : <template> <div> <nav class="navbar navbar-expand-lg fixed-top row"> <router-link tag="li" class="col" class-active="active" to="/" exact>TIME</router-link> <router-link tag="li" class="col" class-active="active" to="/CNN" exact>CNN</router-link> <router-link tag="li" class="col" class-active="active" to="

How to access async store data in vue-router for usage in beforeEnter hook?

核能气质少年 提交于 2019-12-03 02:23:49
How is it possible to access store data in beforeEnter which is retrieved asynchronously via the store action? import store from './vuex/store'; store.dispatch('initApp'); // in here, async data will be fetched and assigned to the store's state // following is an excerpt of the routes object: { path: '/example', component: Example, beforeEnter: (to, from, next) => { if (store.state.asyncData) { // the above state is not available here, since it // it is resolved asynchronously in the store action } } } This is especially important on the first page load or after a page reload, when the init

Vue-Router: TypeError: this._router.init is not a function

匿名 (未验证) 提交于 2019-12-03 01:45:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have vue-router installed (within Laravel project), then try to use it: import VueRouter from 'vue-router' Vue.use(VueRouter) then I get this: [Vue warn]: Error in beforeCreate hook: "TypeError: this._router.init is not a function" Interestingly enough, everything was fine previously, but suddenly started getting this message. 回答1: Replace vue with vue-loader in your Webpack config https://github.com/vuejs/vue-loader/issues/409 UPDATE Okay, obviously you are not initializing the router in a proper way require('./bootstrap'); import Vue

vue-router总结

痴心易碎 提交于 2019-12-03 01:32:00
一、文件目录说明 main.js:应用的入口文件【js文件入口】 App.vue:根组件,整个组件的入口【组件文件入口】 new Vue({}); //Vue是构造函数,本质上是一个函数,函数就有原型prototype 加载文件不要后缀名: resolve:{ extensions:['.js','.vue','.json'], alias:{ 'vue$':'vue/dist/vue.esm.js', '@':resolve('src') //@就代表了"src"这个目录 } } import App from './App'; 就相当于 './App.vue'; import router from './router' //加载某个目录下的index.js文件,可以简写,就相当于 './router/index.js' .gitignore 上传git仓库的时候,不上传某些文件,比如node_modules,因为太大了, 所以从git仓库clone文件下来的时候,首先就是要npm install,安装package.json里面定义的依赖包 然后就是npm run dev index.js文件,定义路由(默认导出) export default new Router({}) 也可以: let router = new Router({}) //先定义,下面导出

Passing props with programmatic navigation Vue.js

眉间皱痕 提交于 2019-12-03 01:26:05
I have a Vue component that has a prop named 'title' e.g: <script> export default { props: ['title'], data() { return { } } } </script> I navigate to the component programmatically after a certain action is complete. Is there a way to programmatically route a user while also setting the prop value? I know you can create a link like this: <router-link to="/foo" title="example title">link</router-link> However, is there a way to do something like the following? this.$router.push({ path: '/foo', title: 'test title' }) EDIT: As suggested I've changed my route to the following: { path: '/i/:imageID

Can vue-router open a link in a new tab?

匿名 (未验证) 提交于 2019-12-03 01:10:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a summary page and a detail subpage. All of the routes are implemented with vue-router (v 0.7.x) using programmatic navigation like this: this.$router.go({ path: "/link/to/page" }) However, when I route from the summary page to the subpage, I need to open the subpage in a new tab just as one would by adding _target="blank" to an <a> tag. Is there a way to do this? 回答1: I think that you can do something like this: let routeData = this.$router.resolve({name: 'routeName', query: {data: "someData"}}); window.open(routeData.href, '_blank')

Vue.js page transition fade effect with vue-router

南笙酒味 提交于 2019-12-03 01:02:35
问题 How to achieve a fade effect page transition between vue-router defined pages (components)? 回答1: Wrap <router-view></router-view> with <transition name="fade"></transition> and add these styles: .fade-enter-active, .fade-leave-active { transition-property: opacity; transition-duration: .25s; } .fade-enter-active { transition-delay: .25s; } .fade-enter, .fade-leave-active { opacity: 0 } Detailed answer Assuming you have created your application with vue-cli, e.g.: vue init webpack

Vue-Router Passing Data with Props

混江龙づ霸主 提交于 2019-12-03 00:37:08
I am having a hard time passing props using Vue-Router. I seem to not be able to access the props when I bring them into the next view. This is my methods object: methods: { submitForm() { let self = this; axios({ method: 'post', url: url_here, data:{ email: this.email, password: this.password }, headers: { 'Content-type': 'application/x-www-form-urlencoded; charset=utf-8' } }).then(function(response) { self.userInfo = response.data; self.$router.push({name: 'reading-comprehension', props: {GUID:self.userInfo.uniqueID }}); }) } } The post request is working, but when I try to route to a new