Vue 路由router
简单案例:
App.vue是核心组件,其中的<router-link>相当于a标签,to相当于href,export是暴露函数,这样某组件才能被其他组件识别到
代码:

<template>
<div id="app">
<img src="./assets/logo.png"> <h1>hello!!!!!!!!!!!!!</h1>
<!-- 路由路径 这里!!!-->
<router-link to="/main">首页</router-link>
<router-link to="/content">内容页</router-link>
<router-view></router-view>
</div>
</template>
<script>
export default {
name: 'App'
}
</script>
<style>
#app {
font-family: 'Avenir', Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
}
</style>
index.js中通过routes定义路由路径和要跳转的组件

import Vue from "vue";
import VueRouter from "vue-router";
import Content from "../components/Content.vue";
import Main from "../components/Main.vue"; //安装路由
Vue.use(VueRouter); //配置导出路由
export default new VueRouter({
routes:[
{
//路由路径,这里!!!
path:'/content',
name:'content',
//跳转的组件
component:Content
},
{
//路由路径
path:'/main',
name:'content',
//跳转的组件
component:Main
}
]
})
Main.vue相当于后端的jsp页面,前端的html页面

<template>
<h1>我是主页</h1>
</template>
<script>
export default {
name: "Main"
}
</script>
<style scoped>
</style>
Content.vue

<template>
<h1>我是内容页</h1>
</template>
<script>
//暴露
export default {
name: "Content"
}
</script>
<style scoped>
</style>
在终端运行之
npm run dev
运行结果:


流程:用户在App.vue核心点击超链--> 到index.js拿到路由映射路径 --> 寻找组件目录下对应的.vue文件,index.js相当于中间商
注意:main.js文件的作用相当于全局配置,配置路由和核心组件App.vue,一旦确定一般不用再改动
Vue 路由router的更多相关文章
- vue路由-router
VueRouter基础 vue路由的注册 导入 <script src="https://unpkg.com/vue-router/dist/vue-router.js"&g ...
- 单页vue路由router
Vue.js + vue-router 可以很简单的实现单页应用. <router-link> 是一个组件,该组件用于设置一个导航链接,切换不同 HTML 内容. to 属性为目标地址, ...
- vue路由router的三种传参方式
方法三: 传参页面传递参数方式: this.$router.push({ path: 'indexTwoDetails', query: { "id": id } }) 接受参数页 ...
- vue项目创建步骤 和 路由router知识点
菜单快捷导航: vue项目创建 vue路由router知识点(路径参数.查询参数.命名路由.嵌套路由.命名视图.hash/history模式) 1.创建一个vue项目步骤 (windows环境下).创 ...
- vue 路由动态传参 (多个)
动态传参 传值页面 客户列表clientList.vue 路由 router.js 配置路由 接收参数的页面 客户详情CustomerDetails.vue 通过this.$router.para ...
- vue路由请求 router
创建一个Router.js文件 // 路由请求//声明一个常量设置路菜单// import Vue from "vue/types/index";import Vue from ' ...
- Vue之单文件组件的数据传递,axios请求数据及路由router
1.传递数据 例如,我们希望把父组件的数据传递给子组件. 可以通过props属性来进行传递. 传递数据三个步骤: 步骤1:在父组件中,调用子组件的组名处,使用属性值的方式往下传递数据 <Menu ...
- react router @4 和 vue路由 详解(八)vue路由守卫
完整版:https://www.cnblogs.com/yangyangxxb/p/10066650.html 13.vue路由守卫 a.beforeEach 全局守卫 (每个路由调用前都会触发,根据 ...
- react router @4 和 vue路由 详解(一)vue路由基础和使用
完整版:https://www.cnblogs.com/yangyangxxb/p/10066650.html 1.vue路由基础和使用 a.大概目录 我这里建了一个router文件夹,文件夹下有in ...
- react router @4 和 vue路由 详解(全)
react router @4 和 vue路由 本文大纲: 1.vue路由基础和使用 2.react-router @4用法 3.什么是包容性路由?什么是排他性路由? 4.react路由有两个重要的属 ...
随机推荐
- 声网王浩宇:RTE 场景下的 Serverless 架构挑战【RTE 2022】
前言 在「RTE2022 实时互联网大会」中,声网云原生边缘计算团队的负责人 @王浩宇 Dylan 以<RTE 场景下的 Serverless 架构挑战 -- 声网如何兼顾后端服务的可靠.高效和 ...
- 一次.net code中的placeholder导致的高cpu诊断
背景 最近一位朋友找到我,让我帮看他们的一个aspnet core service无端cpu高的问题.从描述上看,这个service之前没有出现过cpu高的情况,最近也没有改过实际的什么code.很奇 ...
- 阿里云OSS前端直传+net core后端签名
OSS前端直传+后端签名 一.服务端签名后前端直传 首先安装阿里云SDK Aliyun.OSS.SDK.NetCore public static string accessKeyId = " ...
- 一个bug重温对JRE和JDK的关系思考
前几天做一个springboot项目时,导入的JAVA版本是17,然后后面想更贴近下企业中使用的JDK版本就改成了JDK 1,8,然后就编译错误,bug如下 java: java.lang.Unsup ...
- 股票数据定向爬虫.py(亲测有效)
import requests from bs4 import BeautifulSoup import traceback import re def getHTMLText(url,code='u ...
- 浅谈Vue 2.x当中组件之间传值方式
一.父子之间传值 1. 父传子 :props <!DOCTYPE html> <html lang="en"> <head> <meta ...
- 部署:windows7下mysql8.0.18部署安装
一.前期准备(windows7+mysql-8.0.18-winx64) 1.下载地址:https://dev.mysql.com/downloads/ 2.选择直接下载不登录账号,下载的压缩包大概两 ...
- mongoDB操作指南
目录 1. docker安装mongoDB 2. 库-database 3. 集合-collection 3.1 命名规范 3.2 增-createCollection 3.3 删-drop 4. 文 ...
- Redis(三)jedis与锁
1 Jedis 引入依赖 <dependency> <groupId>redis.clients</groupId> <artifactId>jedis ...
- pytorch图像处理基础
pytorch 图像预处理transforms from torchvision.transforms import transforms transforms.Compose() 作用:将一系列的t ...