<template> <div class="nav_wrapper"> <div ref="navContainer" class="nav_container"> <div class="nav_item" v-on:click="onClick(item)" v-for="(item,index) in Navs" :key="index"> {{item.title}} </div> <div class="nav_footer_cursor" :style="{ Num, left:Left }" ></div> </div> </div> </template>
<script> import {mapState} from "vuex"; export default { data(){ return{ Left:"10px", Num:"64px" } }, computed:mapState({ Navs:"Navs"//这是拿到的导航列表 }), methods:{ onClick(obj){ let num=window.event.target.offsetWidth; let positionNum=window.event.target.offsetLeft; // window.console.log(positionNum) this.Num=num+"px"; this.Left=positionNum+"px"; this.$store.dispatch("SortGoods",obj) } } } </script>
<style scoped> .nav_wrapper { 100%; height:40px; margin-top:64px; } .nav_item { 100px; height:40px; text-align: center; white-space: nowrap; padding:0 10px; } .nav_container::-webkit-scrollbar{ display: none; } .nav_container { 100%; display: flex; position: relative; overflow: scroll; white-space: nowrap; } .nav_footer_cursor { 100%; height:3px; border-radius:3px; background: red; position: absolute; margin-top:20px; transition: all 0.3s linear 0.1s; } </style>