当前位置: 首页 > news >正文

vue2简单的路由切换

1:安装路由指定版本3


 

在 cmd 黑窗口输入:
vue create vue2_Routenpm install vue-router@3.6.5

2:再新建的项目下创建:

index.js:

import Vue from 'vue'
import VueRouter from 'vue-router'Vue.use(VueRouter)const routes = [{path: '/',name: 'Home',component: () => import('@/views/Home.vue')},{path: '/about',name: 'About',component: () => import('@/views/About.vue')},{path: '/contact',name: 'Contact',component: () => import('@/views/Contact.vue')}]const router = new VueRouter({mode: 'history',routes})export default router

main,js:
 

import Vue from 'vue'
import App from './App.vue'
import router from './route/index'Vue.use(router)Vue.config.productionTip = falsenew Vue({render: h => h(App),router
}).$mount('#app')

About.vue:

<template ><div class="about"><h1>About</h1><p>This is the about page</p><router-link to="/">Go to Home</router-link></div>
</template>
<script>
export default {name: '',components: {},mixins: [],props: {},data() {return {}},computed: {},watch: {},mounted() {},methods: {}
};
</script>
<style  scoped>
.about {text-align: center;margin-top: 50px;font-size: 24px;color: #333;font-weight: bold;text-shadow: 1px 1px 1px #ccc;padding: 20px;border-radius: 5px;box-shadow: 0 0 10px #ccc;   background-color: #f5f5f5;position: relative;z-index: 1;overflow: hidden;transition: all 0.3s ease-in-out;}
</style>


Contact.vue:

<template><div class="contact"><h1>Contact</h1><p>This is the contact page</p><router-link to="/">Go back</router-link></div>
</template>
<script>
export default {name: '',components: {},mixins: [],props: {},data() {return {}},computed: {},watch: {},mounted() {},methods: {}
};
</script>
<style  scoped>.contact {text-align: center;padding: 20px;background-color: #f2f2f2;border-radius: 5px;margin-top: 50px;margin-bottom: 50px;box-shadow: 0 0 10px rgba(0,0,0,0.1);h1 {margin-top: 0;}p {margin-bottom: 20px;font-size: 18px;line-height: 1.5;}}   
</style>


Home.vue:

<template><div class="home-page"><h1>Home Page</h1><p>Welcome to the Home Page</p></div>
</template>
<script>
export default {name: "",components: {},mixins: [],props: {},data() {return {};},computed: {},watch: {},mounted() {},methods: {},
};
</script>
<style  scoped>
.home-page {text-align: center;padding: 20px;background-color: #f5f5f5;border-radius: 5px;margin-top: 50px;margin-bottom: 50px;
}
h1 {font-size: 36px;margin-bottom: 20px;
}
p {font-size: 24px;margin-bottom: 20px;
}
</style>

App.vue:

<template><div id="app"><div class="links"><router-link to="/">去首页</router-link><router-link to="/Contact">去中心</router-link><router-link to="/About">去About</router-link></div><router-view></router-view></div>
</template>
<script>
export default {name: "App",components: {},mixins: [],props: {},data() {return {};},computed: {},watch: {},mounted() {},methods: {},
};
</script>
<style scoped>
#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;
}
.links {margin-bottom: 30px;
}
.links a {display: inline-block;margin: 0 15px;color: #2c3e50;text-decoration: none;
}
.links a:hover {color: #1abc9c;
}
.router-view {display: flex;justify-content: center;align-items: center;height: 100vh;}
</style>

http://www.lqws.cn/news/525043.html

相关文章:

  • OpenCV图像旋转:单点旋转与图片旋转
  • Windows10中设置多个虚拟IP方法
  • Linux size命令详解
  • Boss:攻击
  • Azure虚拟机添加磁盘
  • Docker、Docker composer与Docker desktop
  • H5录音、图文视频IndexDB储存最佳实践:用AI生成语音备忘录
  • Fisco Bcos学习 - 开发第一个区块链应用
  • 高防IP能不能防住500GDdos攻击
  • AI系列1-1: 离线部署通义大模型及持续修正-RedHat+NVIDA GPU
  • Java课后习题(编程题)
  • SpringBoot高校党务系统
  • 激光雷达全链路光学系统及探测器能量耦合分析
  • python的少数民族音乐网站系统
  • request这个包中,get 这个方法里传入的是params ,post这个方法里传入的是data 和 json。这个区别是什么?
  • HarmonyOS5 如何性能优化?
  • Vue Devtools “Open in Editor” 配置教程(适用于 VSCode 等主流编辑器)
  • PyTorch RNN实战:快速上手教程
  • 笔记03:布线-过孔的调用与添加
  • 求助deepsee 生成语法树代码
  • matlab机器人工具箱(Robotics Toolbox)安装及使用
  • 使用node的mysql模块操作MySQL数据库
  • 多传感器标定简介
  • Linux驱动学习day7
  • 【kubernetes】--Service
  • C# LINQ语法
  • Redis—持久化
  • 使用亮数据网页抓取API自动获取Tiktok数据
  • C++包管理工具:conan2使用教程
  • 网络安全技术期末考试