vue-router

vue.js get route name in App.vue

情到浓时终转凉″ 提交于 2019-12-04 18:56:38
问题 I used vue-cli with webpack to build up the vue project. Then I installed vue-meta-info to set up the seo. I want to set up the Page title with the templates and the route name. However , I cannot get the variable in router. rotuer/index.js import Vue from 'vue'; import Router from 'vue-router'; import HelloWorld from '@/components/HelloWorld'; Vue.use(Router); export default new Router({ mode: 'history', routes: [ { path: '/', name: 'HelloWorld', component: HelloWorld, }, ], }); App.vue

Component `mounted` fires twice on page load

∥☆過路亽.° 提交于 2019-12-04 18:48:55
问题 I have a very weird error where on page load a components mounted and beforeMount fire/run twice? Each of my components represents a page, so when I load the page on mywebsite.com/contact the Contact.vue functions mounted and beforeMount fire/run twice but if I load the page on mywebsite.com/foo the Contact.vue functions mounted and beforeMount fire/run once (which is what I think? should happen). Any idea why these functions would execute twice? I have a bit of finicky setup but it work

vue-router.esm.js?fe87:2007 Uncaught (in promise) NavigationDuplicated {_name: \"NavigationDuplicated\", name: \"NavigationDuplicated\"}

爱⌒轻易说出口 提交于 2019-12-04 17:52:29
路由报错 两种解决方法 解决方法一:经过多次尝试发现原因可能是 在重新下载依赖包时,安装的vue-router还是之前出错的那个版本, 解决方法也很简单,在项目目录下运行 npm i vue-router@3.0 -S 即可。 解决方法二:如果你不想用方法一那就在 main.js里添加一段代码。 import Router from 'vue-router' const routerPush = Router.prototype.push Router.prototype.push = function push(location) { return routerPush.call(this, location).catch(error=> error) } 来源: https://www.cnblogs.com/wxqworld/p/11876123.html

Vue_路由vue-router

别来无恙 提交于 2019-12-04 15:18:01
1.场景模拟 现在我们来实现这样一个功能: 一个页面,包含登录和注册,点击不同按钮,实现登录和注册页切换: 1.1 编写父组件 为了让接下来的功能比较清晰,我们先新建一个文件夹:src 然后新建一个HTML文件,作为入口:index.html 然后编写页面的基本结构: <div id="app"> <span>登录</span> <span>注册</span> <hr/> <div> 登录页/注册页 </div> </div> <script src="../node_modules/vue/dist/vue.js"></script> <script type="text/javascript"> var vm = new Vue({ el:"#app" }) </script> 样式: 1.2 编写登录及注册组件 接下来我们来实现登录组件,以前我们都是写在一个文件中,但是为了复用性,开发中都会把组件放入独立的JS文件中,我们新建一个user目录以及login.js及register.js: 编写组件,这里我们只写模板,不写功能。 login.js内容如下: const loginForm = { template:'\ <div>\ <h2>登录页</h2> \ 用户名:<input type="text"><br/>\ 密码:<input type="password">

VueRouter爬坑第一篇-简单实践

柔情痞子 提交于 2019-12-04 15:16:26
VueRouter系列的文章示例编写时,项目是使用vue-cli脚手架搭建。 项目搭建的步骤和项目目录专门写了一篇文章: 点击这里进行传送 后续VueRouter系列的文章的示例编写均基于该项目环境。 VueRouter系列文章链接    《VueRouter爬坑第一篇》-简单实践   《VueRouter爬坑第二篇》-动态路由   《VueRouter爬坑第三篇》-嵌套路由 阅读目录 一.安装VueRouter   1.npm 安装VueRouter   2.如何使用VueRouter 二.组件和路由之间的映射   1.<router-link>编写可以跳转的url   2.编写跳转的目的组件   3.定义路由   4.入口文件main.js配置路由   5.配置组件渲染的位置 三.总结 一.安装VueRouter 1.npm 安装VueRouter   安装命令:npm install vue-router    2.如何使用VueRouter   安装完成之后,需要有两个步骤才能使用   第一步:引入vue-router        第二步:将组件注册到全局(全局注册后,在别的组件中可以直接使用,无需单独引入)        这块先贴出步骤,暂时不写代码,后面做组件和路由映射的时候在把代码写上。 二.组件和路由之间的映射   接着我们的疑问就来了:

vue 路由配置

▼魔方 西西 提交于 2019-12-04 13:34:20
第一步:下载安装vue-router插件 npm install vue-router --save 以下都是在main.js中操作 第二步:在main.js文件中引入插件并且使用 import VueRouter from 'vue-router' Vue.use(VueRouter) 第三步:创建路由组件,在components文件夹中创建任意测试组件, 我创建的是 foo.vue 和bar.vue 然后import引入 第四步:(在main.js中进行操作) ①配置参数 const routes = [ {path:'/foo',component:foo} ] ② 实例化 vueRouter const router = new VueRouter({ routes}) //第五步中花括号里面的的routes要上面的同名 ③ 挂载路由 new Vue({ router, render: h => h(App), }).$mount('#app') 第五部: 接下来转移到App.vue 使用<router-link to="/foo"></router-link> 标签进行导航,to你在main.js里定义的path 加上标签 <router-view></router-view>渲染路由组件 App.vue <template> <div id="app"> <h1

Django - serving a SPA from static folder

戏子无情 提交于 2019-12-04 11:42:11
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 code when I view source, but only at http://localhost:8000/static/console/index.html 1) this won't work

VueJS role based authentication with router

血红的双手。 提交于 2019-12-04 09:51:38
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 achieve this? I'm new to vueJS and I have no idea where to put these if conditions. Here is my code

Vue.js Multiple definitions of a property not allowed in strict mode

本小妞迷上赌 提交于 2019-12-04 09:36:56
Good day. We are building our application using Vuejs/Vuex/vue-router using the https://github.com/vuejs/vue-hackernews-2.0 When building and viewing our application using IE11 we get a SCRIPT1046: Multiple definitions of a property not allowed in strict mode and it references the compiled app.[#hash].js file. I have tracked the duplicate property to the following in the component: <div class="form-group form-group-list"> <label aria-labelledby="Shopping preference">Shopping preference</label> <ul class="inline"> <li> <label for="users__secondary_signup__gender__female" aria-labelledby="Gender

学习记录(day12-container容器布局、侧边导航栏)

余生长醉 提交于 2019-12-04 08:00:00
container容器布局、侧边导航栏 index.js import Vue from 'vue' import VueRouter from 'vue-router' Vue.use(VueRouter) const routes = [ { path:'/', redirect:'/studentList' }, { path: '/studentList', component: () => import('../views/StudentList.vue') }, { path: '/studentAdd', component: () => import('../views/StudentAdd.vue') } ] const router = new VueRouter({ mode: 'history', base: process.env.BASE_URL, routes }) // 对路由默认push方法进行增强--添加catch // 1 获得原始push (缓存) const originalPush = VueRouter.prototype.push // 2 重写vue-router push函数 VueRouter.prototype.push = function push(location) { // 3 执行 原始push函数,如果有异常