用vue写一个页面,包含上方header栏,内容栏有六个方框,里面分别写的是xxx调查问卷模板,点击方框可跳转到相应页面,鼠标悬停到方框上,方框边缘变成淡绿色,所有代码写到一个页面里
时间: 2023-06-10 08:08:34 浏览: 90
以下是一个简单的示例:
```html
<template>
<div>
<header>Header 栏</header>
<div class="container">
<div class="box" v-for="(item, index) in boxes" :key="index" :class="{ active: activeIndex === index }" @mouseover="activeIndex = index" @mouseleave="activeIndex = -1" @click="goToPage(item.link)">
{{ item.title }}
</div>
</div>
</div>
</template>
<script>
export default {
data() {
return {
boxes: [
{
title: "问卷模板 1",
link: "/template1"
},
{
title: "问卷模板 2",
link: "/template2"
},
{
title: "问卷模板 3",
link: "/template3"
},
{
title: "问卷模板 4",
link: "/template4"
},
{
title: "问卷模板 5",
link: "/template5"
},
{
title: "问卷模板 6",
link: "/template6"
}
],
activeIndex: -1
};
},
methods: {
goToPage(link) {
// 跳转到对应页面
this.$router.push(link);
}
}
};
</script>
<style>
.container {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
margin: 20px;
}
.box {
width: 30%;
height: 100px;
border: 1px solid #ccc;
display: flex;
justify-content: center;
align-items: center;
font-size: 20px;
cursor: pointer;
}
.active {
border-color: #9fdf9f;
}
</style>
```
这是一个简单的 Vue 单文件组件,包含一个 header 栏和六个方框。方框使用 `v-for` 指令循环渲染,使用 `@mouseover` 和 `@mouseleave` 监听鼠标悬停事件,使用 `@click` 监听点击事件,并根据 `link` 属性进行页面跳转。同时,使用 `:class` 绑定一个 `active` 类,当鼠标悬停时添加该类,方框边缘变成淡绿色。
注:该示例中使用了 Vue Router 进行页面跳转,需要在项目中安装和配置。
阅读全文