vue-router路由实现页面的跳转
2023-09-14 09:07:25 时间
1、项目结构
2、定义组件
组件1 Login.vue
<template>
<form>
账号:<input type="text">
密码: <input type="text" >
</form>
</template>
<script>
export default {
name: "login"
}
</script>
<style scoped>
</style>
组件2 Main.vue
<template>
<h1>这里是主界面</h1>
</template>
<script>
export default {
name: "Main"
}
</script>
<style scoped>
</style>
3、定义路由
import Vue from 'vue'
import Router from 'vue-router'
import Main from '../components/Main'
import Login from '../components/Login'
Vue.use(Router)
export default new Router({
routes: [
{
path:'/main',
component:Main
},
{
path:'/login',
component:Login
}
]
})
4、定义首页
<template>
<div id="app">
<router-link to="/login">login</router-link>
<router-link to="/main">main</router-link>
<h1>大家好</h1>
<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>
5、效果展示
相关文章
- vue 如何关闭 eslint 检查
- Vue中嵌入LayUI框架
- Vue(27)vue-codemirror实现在线代码编译器「建议收藏」
- Vue笔记(8)
- Vue 定时器/定时调用
- vue 时间戳转换成yyyy-MM-dd hh:mm[通俗易懂]
- vue父组件引入子组件_vue子组件传递方法给父组件
- vue关闭eslint检测_eslint with error prevention
- vue 调用子组件方法失败_Vue子组件调用父组件的方法及常见问题「建议收藏」
- vue中的懒加载和按需加载_vue 路由懒加载
- Vue路由嵌套控制台发出警告Named Route ‘Home‘ has a default child route. When navigating to this named route (:to
- vue.js客服系统实时聊天项目开发(一)路由与子路由-全局变量-elementui搭建基本框架
- vue实现路由懒加载几种方式
- vue.js客服系统实时聊天项目开发(二十二)vue项目中router.js路由介绍
- vue嵌套路由子路由 path 注意
- 4. 「vue@2.6.11 源码分析」new Vue() 整体流程和组件渲染之前的准备工作
- Vue的beforeRouteEnter如何使用组件实例的方法
- vue.js入门篇之Vue.js 样式绑定
- Vue框架下的Redis调用实战(vue调用redis)
- Vue如何连接Redis(vue怎么连接Redis)
- Vue结合Redis实现性能优化(vue引入redis)
- 从零开始Vue项目中使用Redis(vue使用redis)
- Vue搭配Redis做针对性取值(vue redis取值)