vue-router

vue-router

南楼画角 提交于 2019-12-06 11:27:31
vue-router通过 hash 与 History interfac e两种方式实现前端路由,更新视图但不重新请求页面”是前端路由原理的核心之一,目前在浏览器环境中这一功能的实现主要有两种方式 hash ---- 利用URL中的hash(“#”) 利用 History interface在 HTML5中新增的方法;History.pushState() 那么,我们要选择用哪种方式呢? 在vue-router中,它提供mode参数来决定采用哪一种方式,选择流程如下: mode 参数: let routes = [{ path:'/', redirect:'/index', meta:{title:'index',keepLive:true} }, { path:'/index', component:require('./views/index.vue'), meta:{title:'index',keepLive:true} } ] let router = new Router({ mode:'hash', routes:routes }) 默认hash history 注:如果浏览器不支持history新特性,则采用hash方式 如果不在浏览器环境则使用abstract(node环境下) 来源: oschina 链接: https://my.oschina.net

vue.js multiple transitions for a router-view

*爱你&永不变心* 提交于 2019-12-06 10:09:47
If I have a vue-router 'router-view' element defined like this: <router-view transition="slide"> Is there a way to change the transition to a 'fade' when a specific route is called? Use a dynamic binding fopr transition: <router-view :transition="$route.transition"> And set the data of transition from your route data router.map({ '/specialroute': { component: { ... }, transition: 'fade' } }) 来源: https://stackoverflow.com/questions/38776733/vue-js-multiple-transitions-for-a-router-view

VueRouter爬坑第三篇-嵌套路由

99封情书 提交于 2019-12-06 09:35:47
VueRouter系列的文章示例编写时,项目是使用vue-cli脚手架搭建。 项目搭建的步骤和项目目录专门写了一篇文章: 点击这里进行传送 后续VueRouter系列的文章的示例编写均基于该项目环境。 VueRouter系列文章链接    《VueRouter爬坑第一篇》-简单实践    《VueRouter爬坑第二篇》-动态路由    《VueRouter爬坑第三篇》-嵌套路由 阅读目录 一.前言-从需求出发 二.需求实现   1.菜单   2.产品列表   3.产品详情 三.主角-嵌套路由 四.总结 一.前言-从需求出发   假设我们有这样一个需求和界面布局:      左边是菜单区域,点击菜单栏的【产品】,右边内容区上面显示产品列表,点击某个产品名称下面显示产品详情。   emmmm,突然想想这个需求造的有点鸡肋,但是也是为了从一个问题出发好去理解接下来的内容。   仔细想一想,大致的思路如下:   1.菜单是公共内容,我们放入App.vue组件中实现逻辑和页面布局,点击菜单栏的菜单名称使用<router-link>和<router-view>去显示产品列表。   2.产品列表需要新建组件:Content.vue。该组件中编写产品列表的代码,点击产品名称展示产品详情使用<router-link>和<router-view>去显示产品详情。   3.产品详情需要新建组件

Laravel Vue js spa application

…衆ロ難τιáo~ 提交于 2019-12-06 09:04:30
1). i want to know why people use two servers to make a vuejs SPA with laravel. I think we can use the other way. Make a Route like this Route::get('{any}', function () { return view('index'); })->where('any' , ".*"); and let vue handle the page url.. why people are using 2 servers and then using laravel passport to authenticate when we dont need to do all this to make spa.. 2). Okay now suppose we have our spa readdy using 2 separate servers one for vue and one for laravel . Now i don't know how to set two servers on a single remove server.? how should i upload both vue and laravel

vue-router的push和replace的区别

给你一囗甜甜゛ 提交于 2019-12-06 08:00:01
1.this.$router.push() 描述:跳转到不同的url,但这个方法会向history栈添加一个记录,点击后退会返回到上一个页面。 2.this.$router.replace() 描述:同样是跳转到指定的url,但是这个方法不会向history里面添加新的记录,点击返回,会跳转到上上一个页面。上一个记录是不存在的。 3.this.$router.go(n) 相对于当前页面向前或向后跳转多少个页面,类似 window.history.go(n)。n可为正数可为负数。正数返回上一个页面 来源: https://www.cnblogs.com/smile6542/p/11969949.html

Vue router keep iframe dom element (just hide, don't destroy)

白昼怎懂夜的黑 提交于 2019-12-06 07:46:31
I'm developing a Vue 2.5 SPA using vue-router 3.0. Some views contain subcomponents that render iframes. When I switch to another route and return to a route that renders an iframe, the respective iframe is reloaded , even if it was visited before. This behavior is unwanted because it results in a bad UX in that case. The iframe state shall remain the same as before, when the user returns to the view. I guess the reloading is caused by the dom being destroyed when leaving the route. Even the following structure doesn't prevent it: <keep-alive> <router-view></router-view> </keep-alive> <keep

Django - serving a SPA from static folder

本小妞迷上赌 提交于 2019-12-06 07:19:52
问题 Our django server is our API as well as an operations backend. I'm working on improving our ops backend by writing a Vue SPA that slowly replaces the existing ops backend. I'm frontend and a little lost in intricacies of Django configs. Could someone suggest a sane solution for this problem? I would like for the app to be served out of static folder, and have set: STATICFILES_DIRS = ( os.path.join(BASE_DIR, 'static'), os.path.join(BASE_DIR, '../console/dist'), ) This works and I can see my

vue-router模式history与hash

。_饼干妹妹 提交于 2019-12-06 06:37:20
【重点】   history与hash路由的区别 hash前端路由,无刷新 history 会去请求接口 vue-router 默认 hash 模式 —— 使用 URL 的 hash 来模拟一个完整的 URL,于是当 URL 改变时,页面不会重新加载。 如果不想要很丑的 hash,我们可以用路由的 history 模式,这种模式充分利用 history.pushState API 来完成 URL 跳转而无须重新加载页面。 当你使用 history 模式时,URL 就像正常的 url,例如 http://yoursite.com/user/id ,也好看! 不过这种模式要玩好,还需要后台配置支持。因为我们的应用是个单页客户端应用,如果后台没有正确的配置,当用户在浏览器直接访问 http://oursite.com/user/id 就会返回 404,这就不好看了。 所以呢,你要在服务端增加一个覆盖所有情况的候选资源:如果 URL 匹配不到任何静态资源,则应该返回同一个 index.html 页面,这个页面就是你 app 依赖的页面。 . 【文章参考】 vue-router提供两种模式的原因: vue 是渐进式前端开发框架,为了实现 SPA ,需要引入前端路由系统(vue-router)。前端路由的核心是:改变视图的同时不会向后端发出请求。 为了达到这一目的,浏览器提供了 hash 和

vue-router路由高亮效果

家住魔仙堡 提交于 2019-12-06 06:35:40
审查代码,查看激活类名 (1)设置激活类名样式    (2)也可以在路由文件里配置激活类名的别名    (3)配置别名后再次审查,如下所示      此时可以直接配置active类名样式即可    此时便可以实现路由高亮效果 . 来源: https://www.cnblogs.com/jianxian/p/11965741.html

Vue 爬坑之路(三)—— 使用 vue-router 跳转页面

送分小仙女□ 提交于 2019-12-06 05:25:29
使用 Vue.js 做项目的时候,一个页面是由多个组件构成的 ,所以在跳转页面的时候,并不适合用传统的 href,于是 vue-router 应运 而生。 官方文档: https://router.vuejs.org/zh-cn/essentials/getting-started.html 有很多朋友找我要 demo,但是博客中的这个案例被我删掉了,我只好随手写了一个超简单的 demo,希望能有所帮助 链接: https://pan.baidu.com/s/1pMfi5tD 密码: pjwx 这次的实例主要实现下图的效果: 项目结构: 一、配置 Router 用 vue-cli 创建的初始模板里面,并没有 vue-router,需要通过 npm 安装 cnpm i vue-router -D 安装完成后,在 src 文件夹下,创建一个 routers.js 文件,和 main.js 平级 然后在 router.js 中引入所需的组件,创建 routers 对象 import Home from './components/home.vue' const routers = [ { path: '/home' , name: 'home' , component: Home }, { path: '/' , component: Home }, ] export default