Vue Router (创建 挂载)

创建路由模块

在src目录下创建router.js文件作为模块,该文件中按照如下步骤进行操作

1.导入路由相关函数,具体代码如下:

import{ createRouter,createWebHashHistory } from 'Vue-router'

在上述代码中,从Vue-router中导入了createRouter()createWebHashHistory()两个函数,其中,createRouter()函数用于创建路由实例对象,createWebHashHistory()两个函数用于指定路由的工作模式为Hash模式,另外,如果需要指定路由工作模式为html5模式,可以将create WebHashHistory ()函数换成createWebHistory()函数。

2.导入需要被路由控制的Home组件和About组件,具体代码如下:

import Home from './components/Home.vue'
import About from './componennts/About.vue'

3.创建路由实例对象,具体代码如下

const router = createRouter({
	history: createWebHashHistory(),
	routes: [
		{ path:'/home', components: Home },
		{ path:'/about', components: About },
	]
})

相关推荐

  1. VueRouter

    2024-06-06 23:12:07       39 阅读
  2. <span style='color:red;'>VueRouter</span>

    VueRouter

    2024-06-06 23:12:07      13 阅读
  3. Vue Router (创建 挂载

    2024-06-06 23:12:07       8 阅读
  4. 012vuerouter

    2024-06-06 23:12:07       34 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-06-06 23:12:07       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-06-06 23:12:07       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-06-06 23:12:07       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-06-06 23:12:07       18 阅读

热门阅读

  1. 单片机排水泵高压方案

    2024-06-06 23:12:07       7 阅读
  2. 负载均衡

    2024-06-06 23:12:07       9 阅读
  3. php的default_socket_timeout会不会影响ES连接查询

    2024-06-06 23:12:07       9 阅读
  4. Linux 多台机器之间的免密登录设置

    2024-06-06 23:12:07       9 阅读
  5. Cargo字节镜像源

    2024-06-06 23:12:07       7 阅读
  6. Flappy bird小游戏

    2024-06-06 23:12:07       11 阅读
  7. Spark大数据处理 掌握Scala运算符

    2024-06-06 23:12:07       9 阅读
  8. Debian 常用命令指南:基础篇

    2024-06-06 23:12:07       9 阅读
  9. Scala学习笔记8: 包

    2024-06-06 23:12:07       9 阅读
  10. python随机显示四级词汇 修改版直接显示释义

    2024-06-06 23:12:07       8 阅读