vue-router路由:安装路由:cnpm install vue-router@3.1.3 --save-dev

本文详细介绍了如何使用Vue-router进行页面路由配置。从安装到配置路由规则,再到实际页面间的跳转,一步步展示了Vue-router的基本用法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、Vue-router

安装路由:cnpm install vue-router@3.1.3 --save-dev
在这里插入图片描述

2、运行流程

在这里插入图片描述
在这里插入图片描述

<template>
  <h1>内容页</h1>
</template>

<script>
export default {
  name: "Content"
}
</script>

<style scoped>

</style>

在这里插入图片描述

import Vue from "vue";
import VueRouter from "vue-router";
import Content from "../components/Content";
import main from "../components/main";
import Main from "../components/main";

//安装路由
Vue.use(VueRouter);

//配置导出路由
export default new VueRouter({
  routes:[
    {
      //路由的路径
      path:'/c1',
      name:'content',
      //跳转的组件
      component:Content
    },
    {
      //路由的路径
      path:'/m1',
      name:'main',
      //跳转的组件
      component:Main
    }
  ]
});

在这里插入图片描述

import Vue from 'vue'
import App from './App'
import router from "./router";

Vue.config.productionTip = false;



new Vue({
  el: '#app',
  //配置路由
  router,
  components: { App },
  template: '<App/>'
});

在这里插入图片描述

<template>
  <div id="app">
    <h1>lan</h1>

    <router-link to="/m1">首页</router-link>
    <router-link to="/c1">内容页</router-link>
    <router-view></router-view>

  </div>
</template>

<script>
import Content from "./components/Content";
export default {
  name: 'App',
  comments: {
    Content
  }
}
</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>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值