前言
本人是后端,只会前端三件套,不会vue。但是有个紧急任务就是把原本的一个三件套写的项目转为vue3。所以我用vue-cli创建了一个vue3项目。项目打开的首页是这样的
它导航栏的"合作案例"“服务团队”“联系我们”分别对应着Services.vue、Team.vue、Contact.vue。但是现在没办法点击并跳转。
项目整体结构
![在这里插入图片描述](https://img-blog.csdnimg.cn/direct/18a1d42254d048f394259b839674653a.png =400x)
App.vue
<template>
<div id="app">
<router-view/>
</div>
</template>
main.js
import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
createApp(App).use(store).use(router).mount('#app')
Navbar.vue
<template>
<div class="navbar">
<div class="logo"><a href="#">深圳市淮亚之光科技创新有限公司</a></div>
<ul class="links">
<li><router-link to="/">首页</router-link></li>
<li><router-link to="/services">合作案例</router-link></li>
<li><router-link to="/team">服务团队</router-link></li>
<li><router-link to="/contact">联系我们</router-link></li>
</ul>
<a href="#" class="action_btn">中文/English</a>
<div class="toggle_btn">
<i class="fa-solid fa-bars"></i>
</div>
</div>
<div class="dropdown_menu" :class="{ open: DropdownMenuOpen }">
<li><router-link to="/">首页</router-link></li>
<li><router-link to="/services">合作案例</router-link></li>
<li><router-link to="/team">服务团队</router-link></li>
<li><router-link to="/contact">联系我们</router-link></li>
<li><a href="#" class="action_btn">中文/English</a></li>
</div>
</template>
<script>
export default {
name: "Navbar",
data() {
return {
DropdownMenuOpen: false
};
},
methods: {
handleWindowsResize() {
if (window.innerHeight > 768) {
this.DropdownMenuOpen = false;
}
}
},
mounted() {
window.addEventListener("resize", this.handleWindowsResize);
this.handleWindowsResize();
},
beforeDestroy() {
window.removeEventListener("resize", this.handleWindowsResize);
}
};
</script>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Open Sans', sans-serif;
}
li {
list-style: none;
}
a {
text-decoration: none;
color: #fff;
font-size: 1rem;
}
a:hover {
color: orange;
}
/* 导航栏 */
header {
position: relative;
padding: 0 2rem;
}
.navbar {
width: 100%;
height: 60px;
max-width: 1200px;
margin: 0 auto;
display: flex;
align-items: center;
justify-content: space-between;
}
.navbar .logo a {
font-size: 1.5rem;
font-weight: bold;
}
.navbar .links {
display: flex;
gap: 2rem;
}
.navbar .toggle_btn {
color: #fff;
font-size: 1.5rem;
cursor: pointer;
display: none;
}
.action_btn {
background-color: orange;
color: #fff;
padding: 0.5rem 1rem;
border: none;
outline: none;
border-radius: 20px;
font-size: 0.8rem;
font-weight: bold;
cursor: pointer;
transition: scale 0.2 ease;
}
.action_btn:hover {
scale: 1.05;
color: #fff;
}
.action_btn:active {
scale: 0.95;
}
/* 下拉式菜单 */
.dropdown_menu {
display: none;
position: absolute;
right: 2rem;
top: 60px;
height: 0;
width: 300px;
background: rgba(255, 255, 255, 0.1);
backdrop-filter: blur(15px);
border-radius: 10px;
overflow: hidden;
transition: height 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.dropdown_menu.open {
height: 240px;
}
.dropdown_menu li {
padding: 0.7rem;
display: flex;
align-items: center;
justify-content: center;
}
.dropdown_menu .action_btn {
width: 100%;
display: flex;
justify-content: center;
}
</style>
Index.vue
<template>
<header>
<Navbar></Navbar>
</header>
<main>
<section id="index">
<h1>助力中小企业数字化转型</h1>
<p>品质卓越 共赢至上</p>
</section>
</main>
</template>
<script>
import Navbar from '@/components/Navbar.vue';
export default {
name: 'index',
components: {
Navbar
}
}
</script>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Open Sans', sans-serif;
}
body {
height: 100vh;
background-color: #000;
background-image: url('https://images.unsplash.com/photo-1485470733090-0aae1788d5af?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1517&q=80');
background-size: cover;
background-position: center;
}
li {
list-style: none;
}
a {
text-decoration: none;
color: #fff;
font-size: 1rem;
}
a:hover {
color: orange;
}
/* 导航栏 */
header {
position: relative;
padding: 0 2rem;
}
.navbar {
width: 100%;
height: 60px;
max-width: 1200px;
margin: 0 auto;
display: flex;
align-items: center;
justify-content: space-between;
}
.navbar .logo a {
font-size: 1.5rem;
font-weight: bold;
}
.navbar .links {
display: flex;
gap: 2rem;
}
.navbar .toggle_btn {
color: #fff;
font-size: 1.5rem;
cursor: pointer;
display: none;
}
.action_btn {
background-color: orange;
color: #fff;
padding: 0.5rem 1rem;
border: none;
outline: none;
border-radius: 20px;
font-size: 0.8rem;
font-weight: bold;
cursor: pointer;
transition: scale 0.2 ease;
}
.action_btn:hover {
scale: 1.05;
color: #fff;
}
.action_btn:active {
scale: 0.95;
}
/* 下拉式菜单 */
.dropdown_menu {
display: none;
position: absolute;
right: 2rem;
top: 60px;
height: 0;
width: 300px;
background: rgba(255, 255, 255, 0.1);
backdrop-filter: blur(15px);
border-radius: 10px;
overflow: hidden;
transition: height 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.dropdown_menu.open {
height: 240px;
}
.dropdown_menu li {
padding: 0.7rem;
display: flex;
align-items: center;
justify-content: center;
}
.dropdown_menu .action_btn {
width: 100%;
display: flex;
justify-content: center;
}
/* 首页正文 */
section#index {
height: calc(100vh - 60px);
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
text-align: center;
color: #fff;
}
#index h1 {
font-size: 3rem;
margin-bottom: 1rem;
}
/* 响应式设计 */
@media(max-width: 992px) {
.navbar .links,
.navbar .action_btn {
display: none;
}
.navbar .toggle_btn {
display: block;
}
.dropdown_menu {
display: block;
}
}
@media(max-width: 576px) {
.dropdown_menu {
left: 2rem;
width: unset;
}
}
</style>
Team.vue
<template>
<header>
<div include-html="navbar_eng.html"></div>
</header>
<div class="shell">
<div class="content">
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
</div>
</div>
</template>
<script>
import Navbar from '@/components/Navbar.vue';
export default {
name: 'team',
components: {
Navbar
}
}
</script>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Open Sans', sans-serif;
}
body {
/* display: flex; */
align-items: center;
height: 100vh;
background-color: #000;
background-image: url('https://images.unsplash.com/photo-1485470733090-0aae1788d5af?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1517&q=80');
background-size: cover;
background-position: center;
}
.shell {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
width: 100vw;
height: 200vh;
max-width: 484px;
max-height: 422px;
margin: auto;
color: white;
perspective: 1000px;
transform-origin: center;
display: flex;
justify-content: center;
align-items: center;
}
.content {
display: flex;
justify-content: center;
align-items: center;
width: 100%;
height: 100%;
margin: auto;
transform-origin: center;
transform-style: preserve-3d;
transform: translateZ(-30vw) rotateY(0);
animation: carousel 9s infinite cubic-bezier(0.77, 0, 0.175, 1) forwards;
}
.item {
position: absolute;
width: 60vw;
height: 40vw;
max-width: 380px;
max-height: 250px;
box-shadow: 0 5px 20px rgba(0, 0, 0, 0.3);
border-radius: 6px;
background-size: cover;
-webkit-box-reflect: below 25px -webkit-linear-gradient(transparent 50%, rgba(255, 255, 255, 0.3));
}
.item:nth-child(1) {
background-image: url("../assets/1.jpg");
transform: rotateY(0) translateZ(35vw);
}
.item:nth-child(2) {
background-image: url("../assets/4.jpg");
transform: rotateY(120deg) translateZ(35vw);
}
.item:nth-child(3) {
background-image: url("../assets/3.jpg");
transform: rotateY(240deg) translateZ(35vw);
}
@keyframes carousel {
0%,
17.5% {
transform: translateZ(-35vw) rotateY(0);
}
27.5%,
45% {
transform: translateZ(-35vw) rotateY(-120deg);
}
55%,
72.5% {
transform: translateZ(-35vw) rotateY(-240deg);
}
82.5%,
100% {
transform: translateZ(-35vw) rotateY(-360deg);
}
}
</style>
router包下面的index.js
import { createRouter, createWebHistory } from 'vue-router'
import Index from "../views/Index.vue"
import Contact from '../views/Contact.vue';
import Services from '../views/Services.vue';
import Team from '../views/Team.vue'
const routerHistory = createWebHistory()
const router = createRouter({
history: routerHistory,
routes: [
{
path: '/',
name: 'index',
component: Index
},
{
path: '/contact',
name: 'contact',
component: Contact
},
{
path: '/services',
name: 'services',
component: Services
},
{
path: '/team',
name: 'team',
component: Team
}
]
}
)
想问下前端同学们,该怎么解决这个问题呢?