明梦爽
2022-01-22 ddfc75ed45d427bb8b407133b5e2bde0e6ec581a
src/components/Home.vue
@@ -5,24 +5,14 @@
      <div>
        <img src="../assets/xiaohui4.png" alt="" />
      </div>
      <div class="bg"></div>
      <div>
        <img src="../assets/bg.png" alt="">
      </div>
    </el-header>
    <!-- 主页导航栏 -->
    <el-row>
      <el-menu
        mode="horizontal"
        background-color="rgb(64, 112, 186)"
        text-color="white"
        class="menu"
        active-text-color="#000000"
        :default-active="activeIndex"
        @select="handleSelect"
      >
        <el-menu-item
          :key="index"
          v-for="(item,index) in menuList"
          :index="item.index"
        >
      <el-menu mode="horizontal" background-color="rgb(64, 112, 186)" text-color="white" class="menu" active-text-color="#000000" :default-active="activeIndex" @select="handleSelect">
        <el-menu-item :key="index" v-for="(item, index) in menuList" :index="(item.id).toString()">
          {{ item.name }}
        </el-menu-item>
      </el-menu>
@@ -38,41 +28,81 @@
</template>
<script>
import {getNavList} from '../api/api'
import axios from 'axios'
export default {
  name: '',
  data() {
    return {
      activeIndex: 'index',
      menuList:[
        {index:'index',name:'首页'},
        {index:'introduce',name:'科协概况'},
        {index:'zhengce',name:'政策法规'},
        {index:'keXieXiangMu',name:'科协项目'},
        {index:'xueShuJiaoLiu',name:'学术交流'},
        {index:'banShiZhiNan',name:'办事指南'},
        {index:'kePu',name:'科普风采'},
        {index:'xueXiaoShouYe',name:'学校首页'},
        {index:'telephone',name:'联系我们'},
      ]
      activeIndex: '1',
      menuList: [{name: '首页',id: 1},{name: '科协概况',id: 22},{name: '政策法规',id: 23},{name: '科协项目',id: 24},
      {name: '学术交流',id: 25},{name: '办事指南',id: 26},{name: '科普风采',id: 27},{name: '学校首页',id: 28},
      {name: '联系我们',id: 29}],
      menuList2:[]
    }
  },
  created(){
  created() {
    // this.getNavArr();
  },
  mounted(){
  mounted() {
    let api3 = 'http://localhost:8080/news_type/all'
    axios.get(api3).then((res)=>{
      // console.log(res);
      this.menuList2 = res.data.data
    }).catch((error)=>{
      console.log(error);
    })
  },
  watch:{
  },
  watch: {},
  methods: {
    // //获取导航栏
    // getNavArr(){
    //   const data ={};
    //   getNavList(data).then(res => {
    //     console.log('res', res)
    //     if(res.code == 200){
    //       this.menuList2 = res.data.data
    //     }
    //     this.menuList2 = res.data.data
    //   }).catch(err => {
    //     console.log('err', err)
    //   })
    // },
    formatterTitle(t){
      switch(t){
        case '1':
          return 'index'
        case '22':
          return 'introduce'
        case '23':
          return 'zhengce'
        case '24':
          return 'keXieXiangMu'
        case '25':
          return 'xueShuJiaoLiu'
        case '26':
          return 'banShiZhiNan'
        case '27':
          return 'kePuFengCai'
        case '28':
          return 'xueXiaoShouYe'
        case '29':
          return 'telephone'
      }
    },
    handleSelect(key, keyPath) {
      // console.log(key, keyPath)
      this.$router.push({
        path: '/home/' + key,
        query:{
          title:key
        }
      })
      if (key == '28') {
        window.open('https://www.pdsu.edu.cn/#')
      } else {
        this.$router.push({
          path: '/home/' + this.formatterTitle(key),
          query: {
            title: this.formatterTitle(key),
            id:key
          }
        })
      }
    }
  }
}
@@ -83,25 +113,15 @@
  height: 100%;
}
.el-header {
  background: -webkit-linear-gradient(
    left,
    rgb(5, 102, 141),
    rgb(240, 243, 189)
  );
  background: -o-linear-gradient(right, rgb(5, 102, 141), rgb(240, 243, 189));
  background: -moz-linear-gradient(right, rgb(5, 102, 141), rgb(240, 243, 189));
  background: linear-gradient(to right, rgb(5, 102, 141), rgb(240, 243, 189));
  background-color: rgb(1, 72, 153);
}
.el-header {
  height: 93px !important;
  height: 120px !important;
  padding: 0 80px 0 120px;
  overflow: hidden;
  div {
    display: flex;
    justify-content: left;
  }
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.el-menu {
  .el-menu-item {
@@ -126,7 +146,7 @@
  text-align: center;
  line-height: 60px;
}
.box{
.box {
  width: 1200px;
  margin: 0 auto;
}