vue-router

基础路由的设置——使用vue-router实现导航切换

依然范特西╮ 提交于 2019-12-06 04:16:01
1.vue-router的安装。 命令行中进入项目所在文件位置【重要】,输入: npm install vue-router 安装完成后在项目文件中的package.json中可以看到vue-router的版本信息。 2.在 App.vue中 定义<router-link> 和 <router-view>     在vue-router中, 我们看到它定义了两个标签 <router-link> 和 <router-view> 分别对应点击和显示部分。     <router-link> 就是定义页面中点击的部分,<router-link> 还有一个非常重要的属性 to,定义点击之后,要到哪里去, 如:<router-link to=”/home”>Home</router-link>     <router-view> 定义显示部分,就是点击后,区配的内容显示在什么地方。 App.vue代码: < template > < div > < v-header :seller = "seller" > </ v-header > < div class = "tab border-1px" > < div class = "tab-item" > <!-- router-link 定义点击后导航到哪个路径下 --> < router-link to = "/goods" > 商品 </

VueJS role based authentication with router

那年仲夏 提交于 2019-12-06 04:12:56
问题 My use case is something like this. When someone login to the system, I identify user role at the login action and store that value as a state . I have 3 user roles, namely student , admin and dataEntry I have 3 separates routes for these 3 roles as well.(/student,/admin,/dataEntry) So, I want to route users to the system acroding to their user roles. Logically something like this. if(userType == 'student'){ router.push('/student') }, if(userType == 'admin'){ router.push('/admin') } How do I

vue侧边栏导航,右侧显示对应内容

泄露秘密 提交于 2019-12-06 04:12:30
最终效果 点击下一个导航,上一个导航自动收回 实现代码 1.下载vue-router npm install vue-router --save-dev 2.在main.js中引入 import Vue from 'vue' import Router from 'vue-router' Vue.use(Router) // 引入路由 3.在components中新建组件 3.1 agencySearch.vue组件 代码: <template> <div> 直属下线代理查询 </div> </template> 3.2 agencySet.vue组件 代码 <template> <div> 直属下线代理设置 </div> </template> 3.3 financialIncome.vue组件 代码 <template> <div> 财务收益数据报表 </div> </template> 4.在router下的index.js中引入组件,搭配路由 //4.1引入组件 import Vue from 'vue' import Router from 'vue-router' import Home from '@/components/Home' // 主页 import agencySearch from '@/components/agencySearch' //

Vue Router nested paths break static assets path on manual refresh

折月煮酒 提交于 2019-12-06 03:50:07
问题 We're using VueJS 2.x with the vue-cli Webpack boilerplate, along with Vue Router. We've run into a problem where the following happens Our static assets sit in a root level static folder The assets paths are defined as follows in Webpack config/index.js file: assetsSubDirectory: 'static', assetsPublicPath: '/', Vue Router is running in history mode and we followed the official docs. for including the required Apache rewrite rule while running the router in history mode. In our routes file

iview菜单(Menu)和选项卡(Tabs)的组合应用

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-06 03:46:54
iview菜单(Menu)和选项卡(Tabs)的组合应用 前提 最后成果 总体流程 创建layout布局 将所有router组件进行注册 进行编码 总结 前提 本人学习iview阶段,组合应用的前提要掌握vue,vue-router等基础,本次项目利用的是router-link和router-view进行的操作,才可实现。 最后成果 相对于一些管理系统等,都会有着一定的帮助。 总体流程 创建layout布局 将所有router组件进行注册 进行编码 <template> <Layout class="layout" :style="{minHeight: '100vh'}"> <Sider style="z-index: 5;" width="240" collapsible :collapsed-width="120" v-model="isCollapsed"> <Menu :class="menuitemClasses" active-name="1-1" width="auto" :theme="dark" accordion @on-select="menuSelect" @test='menuSelect' :style="{height:mainHeight+'px'}"> <Submenu v-for="item in menuData" :name="item

Vue路由相关配置

半城伤御伤魂 提交于 2019-12-06 03:43:14
什么是路由?   1、在以前页面跳转使用的是超链接a标签或者js location.href, 而路由是跳转切换组件的跳转方式   2、路由就是监听url的改变并提供相对应的组件用于展示   3、vue-router官方提供的路由, 在vue中vue-router则为vue提供的url监听并提供组件展示的js, 也是vue全家桶中的最重要知识点之一 使用 第一步:引入   引入vue-router   <script></script>标签引入 第二步:创建展示的组件   let news = {     template:"<h1>这是新闻页面</h1>"   } 第三步:创建路由规则    {     //path为要监听的路径     path:"/",     //component为监听到url中是/则提供index这个组件用于展示     component:index   }, 第四步:把上面创建的路由对象添加到Vue实例中 //创建路由对象 let router = new VueRouter({routes})   new Vue({     el:"#app",   data:{},   router }) 第五步:在页面上添加标签<router-view></router-view>为路由渲染组件的容器 第六步:使用<router-link></router

Vue js;Vue router is not constructor error in simple route

僤鯓⒐⒋嵵緔 提交于 2019-12-06 00:44:50
问题 I am trying to implement simple routing with official route library. Here is my app.js window.Vue = require('vue'); window.VueRouter= require('vue-router'); Vue.use(VueRouter); const vt=Vue.component('example', require('./components/Example.vue')); const router = new VueRouter({ routes:[ { path:'/test', component:vt } ] }) const app = new Vue({ el: '#app', router:router }); But i got an error app.js:11256 Uncaught TypeError: VueRouter is not a constructor 回答1: This answer is for any onlookers

How to redirect user inside vue-resource http interceptor?

心不动则不痛 提交于 2019-12-05 23:02:07
问题 I want to redirect the user when I have an 401, but I can't access the router from this context: Vue.http.interceptors.push(function(request, next) { // continue to next interceptor next(function(response) { if(response.status == 401){ //redirect user here //tried: Vue.$router and Vue.$route } }); }); How can I make this? Using: Vue-router and Vue-resource 回答1: const router = new VueRouter({ routes }) Vue.http.interceptors.push(function(request, next) { // continue to next interceptor next

Is there a way to route to html files with Vue router?

谁说我不能喝 提交于 2019-12-05 22:09:29
Hello I am using VueJS and the webpack template. I have a bunch of components I can easily display with Vue Router. However, my organization uses Robot Framework for testing and we generate an HTML page using the command: python -m robot.testdoc /tests/directory /destination.html This is basically how I am using the router: import Vue from 'vue' import Router from 'vue-router' import Main from '@/components/Main.vue' import Component1 from '@/components/Component1.vue' import Component2 from '@/components/Component2.vue' Vue.use(Router) export default new Router({ routes: [ { path: '/', mode:

vue-router Uncaught (in promise) NavigationDuplicated 错误

倖福魔咒の 提交于 2019-12-05 22:00:00
使用 vue-router 编程式实现页面跳转 this.$router.replace({ path: '/pub' }); 出现错误如下图 原因:vue-router 在 3.1 版本之后把 this.$router.replace() 方法改为了 Promise,没有回调函数时错误信息就会由全局显示 解决办法: 1、降低 vue-router 版本到 3.0.7 以下 npm i vue-router@3.0.7 -S 2、给 this.$router.replace() 方法添加回调 this.$router.replace({ path: '/pub' }).catch(() => { }); 注:this.$router.push() 方法也存在同样问题,可以同样处理 来源: https://www.cnblogs.com/laoq112/p/11946832.html