Laravel  
laravel
文档
数据库
架构
入门
php技术
    
Laravelphp
laravel / php / java / vue / mysql / linux / python / javascript / html / css / c++ / c#

vue路由配置

作者:佳凝皓月   发布日期:2025-03-03   浏览:127

// Vue路由配置示例代码

// 首先,确保你已经安装了vue-router
// 使用npm安装:npm install vue-router

import Vue from 'vue';
import Router from 'vue-router';
import Home from './components/Home.vue';
import About from './components/About.vue';

// 安装Vue Router插件
Vue.use(Router);

// 创建路由实例并配置路由规则
const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home
  },
  {
    path: '/about',
    name: 'About',
    component: About
  }
];

// 创建并导出路由实例
export default new Router({
  mode: 'history', // 使用HTML5 History模式,去掉URL中的#
  routes // 等价于routes: routes
});

// 解释说明:
// 1. 我们首先导入了Vue和vue-router库,并且导入了两个组件(Home和About)。
// 2. 使用Vue.use(Router)来安装vue-router插件。
// 3. 定义了一个包含路径、名称和对应组件的路由数组。
// 4. 创建一个新的Router实例,并配置使用history模式以去掉URL中的#号。
// 5. 最后将这个Router实例导出,以便在主应用中使用。

上一篇:vue nginx部署

下一篇:vue foreach循环遍历数组

大家都在看

vue.config.js configu

node.js vue

vue查看版本

vue等待几秒

vue3 setup computed

vue screenfull

vue json.stringify

vue 遍历list

typescript vue

vue 复选框

Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3

Laravel 中文站