vue-router

Access router instance from my service

帅比萌擦擦* 提交于 2019-11-30 19:01:40
I create a auth service ( src/services/auth.js ), with just functions and properties .. export default { login() { ... } ... } Inside login function, I need to redirect user router.go(redirect) How can I retrieve router instance ? Context In my src/main.js file, i create a router .. import VueRouter from 'vue-router' Vue.use(VueRouter) import route from './routes' const router = new VueRouter({ history: false, linkActiveClass: 'active' }) route(router) const App = Vue.extend(require('./App.vue')) In my src/routers.js is just map routes export default function configRouter (router) { router.map

vue移动端项目部署之后,第一次加载页面的时候过慢

我的梦境 提交于 2019-11-30 18:35:07
vue移动端项目部署之后,第一次加载页面的时候过慢,不一定非得首页加载慢,直接访问某个组件加载速度很慢的解决方案 vue按需加载组件 ----3种方法 1. vue异步组件技术 2. es6提案的import() 3.vue按需加载组件-使用webpack require.ensure Vue 打包优化方案(解决 vendor.js 过大的问题) 当打包构建应用时,JavaScript 包会变得非常大,影响页面加载。 一、路由懒加载: 把不同路由对应的组件分割成不同的代码块,然后当路由被访问的时候才加载对应组件,这样就更加高效了。 参考链接: https://router.vuejs.org/zh/guide/advanced/lazy-loading.html 二、不打包第三方库: 减少 vendor.js 的体积,从本质上来解决这种问题。 参考链接: https://segmentfault.com/a/1190000016309142 https://blog.csdn.net/LonewoIf/article/details/87777367 将 vue.js 不打包 externals: { 'vue': 'Vue' } 效果对比 加入 vue.js 不加入 vue.js vendor.js(当前包含 vue-router.js),设置 vue.js不加入打包后

Vue $route is not defined

萝らか妹 提交于 2019-11-30 14:28:49
问题 I'm learning Vue router. And I want to made programmatic navigation (without <router-link> ). My router and view: router = new VueRouter({ routes: [ {path : '/videos', name: 'allVideos', component: Videos }, {path : '/videos/:id/edit', name: 'editVideo', component: VideoEdit }, ] }); new Vue({ el: "#app", router, created: function(){ if(!localStorage.hasOwnProperty('auth_token')) { window.location.replace('/account/login'); } router.push({ name: 'allVideos' }) } }) So by default I push to

Vuejs 2, VUEX, data-binding when editing data

家住魔仙堡 提交于 2019-11-30 13:24:34
问题 I have a user profile section and Im trying to allow the user to edit their information. I am using vuex to store the user profile data and pulling it into the form. The edit form is located in a child component of the userProfile component - which loads the data save commits it to VUEX. So I can populate the form with the data from VUEX, but as soon as I change any values in the form, it changes the value in my parent component as well. I am not committing changes to VUEX until the form is

Vuejs, Difficulties to build with relative path

有些话、适合烂在心里 提交于 2019-11-30 13:10:38
I'm facing difficulties to make a proper build with a relative path when I run npm run build . Resolving assets is easy but I don't know how to configure 2 things: 1/ The assetsPublicPath in config/index.js // see http://vuejs-templates.github.io/webpack for documentation. var path = require('path') module.exports = { build: { env: require('./prod.env'), index: path.resolve(__dirname, '../dist/index.html'), assetsRoot: path.resolve(__dirname, '../dist'), assetsSubDirectory: 'static', assetsPublicPath: '/ONLY_ABSOLUTE_PATH_ARE_ALLOWED/', productionSourceMap: true, // Gzip off by default as many

vue-router - How to get previous page url?

◇◆丶佛笑我妖孽 提交于 2019-11-30 12:09:17
问题 I want to get previous page link or url in vue-router . Like a this. How to do it? const link = this.$router.getPrevLink(); // function is not exist? this.$router.push(link); Near concept is this.$router.go(-1) . this.$router.go(-1); 回答1: All of vue-router's navigation guards receive the previous route as a from argument .. Every guard function receives three arguments: to: Route : the target Route Object being navigated to. from: Route : the current route being navigated away from. next:

how to create a 404 component in vuejs using vue-router

独自空忆成欢 提交于 2019-11-30 11:57:14
问题 I'm new to vuejs and I'm working on my first project with vue. I'm just wondering how I will route to my 404.vue component when the requested url is not found. Any Idea? 回答1: In the routes declaration, I like to add this: [ ... { path: '/404', component: NotFound }, { path: '*', redirect: '/404' }, ... ] Which will imply that if the user is navigated to a path which does not match any routes, it will be redirected to the "404" route, which will contain the "not found" message. The reason I've

Vue Router hosting on apache2

↘锁芯ラ 提交于 2019-11-30 07:28:16
I am hosting my vuejs project on apache server. init project setup router Build and hosted to apache server const router = new VueRouter({ routes: Routes, // relative: true, mode: 'history' }); This runs fine in local, but vue router breaks on server. Example If I run http://example.com and go to http://exmaple.com/sub It works fine but if I refresh the page It will throw 404 Error. Error: connexo From the vue.js documentation page : When using history mode, the URL will look "normal," e.g. http://oursite.com/user/id . Beautiful! Here comes a problem, though: Since our app is a single page

去除vue路由跳转地址栏后的哈希值#

无人久伴 提交于 2019-11-30 07:26:17
去除vue路由跳转地址栏后的哈希值#,我们只需要在路由跳转的管理文件router目录下的index.js中加上一句代码即可去掉哈希值# import Vue from 'vue' //1.引入vue-router import Router from 'vue-router' import find from '../components/find' import mall from '../components/mall' import microshop from '../components/microshop' import cloud from '../components/cloud' import personalcenter from '../components/personalcenter' //2.使用vue-router Vue.use(Router) //3.实例化router这个构造函数 let router = new Router({ //去掉地址中的哈希# mode:"history", //5.映射,什么样的地址跳转到什么样的page routes:[ { //根目录 path:'/', name:'首页', component:mall }, { //发现page path:'/find', name:'发现', component:find

4、vue-router 路由基本使用

安稳与你 提交于 2019-11-30 06:47:11
1、安装路由 npm install vue-router --save-dev 2、引入路由 import VueRouter from 'vue-router' 3、使用路由 Vue.use(VueRouter) const router = new VueRouter({ routes:[ {path:"/",component:Home}, {path:"/helloworld",component:HelloWorld}, ], mode:"history" }) 4、导航到路由地址 <template> <div id="app"> <ul> <li><router-link to="/">Home</router-link></li> <li><router-link to="/helloworld">Hello</router-link></li> </ul> </div> </template> 来源: oschina 链接: https://my.oschina.net/u/2614774/blog/3134582