vue-router

vue-router学习之二

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-15 22:07:21
本文的学习来自技术胖大神的教程: https://jspang.com/ 这里的路由是指SPA (单页应用)的路径管理器。 vue-router 就是 WebApp 的链接路径管理系统。 为什么不能直接用 <a></a> 标签编写链接 呢 ?因为用 Vue做 的都是单页应用,相当于只有一个主的 index.html 页面,所以写 <a></a>标签是不起作用的,必须用vue-router来进行管理。 1 安装并写一个简单的路由 在项目目录下执行: npm install vue-router --save-dev 因为当安装 vue-cli 环境时,默认安装好了路由,就不用再重复安装了。 1.1 解读 router/index.js 文件 (为代码加了注释): import Vue from 'vue' //引入Vue import Router from 'vue-router' //引入vue-router import HelloWorld from '@/components/HelloWorld' //引入根目录下的Hello.vue组件 Vue.use(Router) //Vue全局使用Router export default new Router({ routes: [ //配置路由,这里是个数组 { //每一个链接都是一个对象 path: '/', //链接路径

【可视化】Vue基础

送分小仙女□ 提交于 2019-12-15 19:50:25
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 作者 | Jeskson 来源 | 达达前端小酒馆 Vue简介 Vue框架,框架的作者,尤雨溪,组件化,快速开发的特点。 生命周期 beforeCreate:组件刚刚被创建 created:组件创建完成 生成 beforeMount:挂载之前 mounted:挂载之后 成熟 beforeDestory:组件销毁前调用 destoryed:组件销毁后调用 老年 安装: 全局安装:vue-cli npm install --global vue-cli 创建一个基于webpack模板的新项目 vue init webpack my-project 安装依赖包: cd my-project npm install npm run dev @代表src目录: import Vue from 'vue' import Router from 'vue-router' import Hello from '@/components/Hello' Vue.use(Router) export default new Router({ routes: [ { path: '/', name: 'hello', component: Hello } ] }) 生命周期调用: beforeCreate created

[VUE]关于路由哪些事儿

醉酒当歌 提交于 2019-12-14 23:32:33
什么是路由 之前有个小伙伴面试被问到: 面试官:不用vue能不能写单页面应用? 答:用angular啊(咳咳,开个玩笑),答案确实是可以的,原生js中有个事件叫做onhashchange,可以在window对象上监听这个事件,通过触发事件动态加载js,实现了没有向服务器发起请求却能通过url和页面关联,这就是所谓的前端路由了。 路由反映了url和页面的映射关系 vue路由 言归正传,说说vue-router做路由。 先来个简单的demo: npm i vue-router --save-dev 先通过js手动引入vue-router 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 import Vue from 'vue'import Router from './router5.js'// router.js中代码import Vue from 'vue'import VueRouter from 'vue-router'Vue.use(VueRouter)const home = { template:` <div> <h1>首页路由</h1> </div> `}const details = { template:`<h1>详情路由</h1>`}const

How would I be able to multiple select and pass data in the given format in vue js html?

人盡茶涼 提交于 2019-12-14 03:44:50
问题 I need to pass the data in the given format. rules : [{ name:null, section:null, data : [{head:null,value:null}] }], This is the problem I am facing. Hope somebody could help me sort out a solution. The snippet is given. I need to pass data in the format given above. If another array is needed inside rules[], it is also fine Is another array needed for head and value inside data[]. This will be also fine, if needed. Hoping for a help. Please help me to have a solution. Please change the

Laravel eloquent data or simple props to create a custom Vue-router link in Vue.Js

孤街浪徒 提交于 2019-12-13 20:19:52
问题 I have a SPA made in VUE and Laravel. Laravel returns API request and VUE create the frontend using the received data. In a few cases, I have some HTML code returned as compiled data by API engine having links inside. I would like to use these links in vue router but if I return the API having code like this: JSON code { comment: { 'bla <strong>bla</strong> bla <router-link :to="name:\'page\'">text</router-link>' } } Then I use the JSON code in my component template like: <div v-html={comment

Using nuxt, how do I put the route name in the page title?

眉间皱痕 提交于 2019-12-13 14:42:23
问题 I want to set the page title to a different value for each page. In regular Vue.js, I have done the following: import router from './router' import { store } from './store/store'; router.beforeEach((to, from, next) => { store.mutations.setRoute(to); document.title = store.getters.pageTitle; next(); } How would I get that effect in nuxt? That is, on both initial page load and when changing pages, I want the browser tab's title to change. For instance, from "My App - About" to "My App - Profile

vue-router redirect to default path issue

若如初见. 提交于 2019-12-13 11:54:43
问题 I want to default to a specific page when user navigates to the root path ie when used goes to myapp.com I want to redirect them to myapp.com/defaultpage My current code is index.js import Full from '../containers/Full' import DefaultView from '../views/DefaultView' export default new Router({ mode: 'history', linkActiveClass: 'open active', scrollBehavior: () => ({ y: 0 }), routes: [ { path: '/', redirect: '/defaultview', name: 'home', component: Full, children: [ { path: '/defaultview',

vuejs2: How to pass vuex store to vue-router components

萝らか妹 提交于 2019-12-13 05:25:52
问题 In case when vue-router is not used, store can be passed to child components when declaring new Vue() But I am using both vue-router and vuex . In this case how can I make store available to components . For e.g. my store.js is typical: import Vue from 'vue' import Vuex from 'vuex' import jwt_decode from 'jwt-decode' import axios from 'axios' import VueAxios from 'vue-axios' Vue.use(Vuex); Vue.use(VueAxios, axios); export const store = new Vuex.Store({ state: { jwt: localStorage.getItem('t'),

I can redirect to a different route, but that route doesn't work if I refresh the browser

柔情痞子 提交于 2019-12-13 03:23:42
问题 Through $router.push({ path: /week/${year}/${month}/${day}/ }) I can successfully route/move (not sure about what term to use here) to a different route, with the URL correctly updating. However once there, if I refresh the browser, the routed component becomes empty (and no console error). Any idea what's going on here? Here's my router code: let router = new Router({ mode: 'history', routes: [ ... { path: '/', redirect: '/home', meta: { requiresAuth: true } }, { path: '/week/:year/:month/

Vue - Set different favicon when browser online or offline

让人想犯罪 __ 提交于 2019-12-13 01:53:51
问题 I am trying to set different icons for when my browser is online(Normal logo) and offline(Greyed out logo). I am using Vue JS and I am able to detect online and offline set, I am also able to set different favicon for the different state but the offline icon won't show because my browser does not have internet to fetch the icon. What is the best approach to achieve this? The code I am using is below, btw I am using 'v-offline' to detect online or offline states handleConnectivityChange