导航路由配置(下拉固定定位,二级路由跳转)

Views文件下TypeList.vue代码示例:


module.exports = {
    publicPath:"/",
    outputDir:"dist",
    indexPath:"index.html",
    pages:{
        index:{
            entry:'src/main.js',
            // 来源的模板
            template:"public/index.html",
            fileName:'dist/index.html',
            title:'shopping'
        }
    },
    devServer:{
        // 启用压缩,压缩之后 代码所占的空间比较小了,
        compress:true,
        port:9000,
        host:"0.0.0.0",
        hot:true,
        open:true,
        proxy:{
            "/myApi":{
                target:baseURL+"/api", // 接口地址
                changeOrigin:true,
                pathRewrite:{
                    "^/myApi":""
                }
            }
        }
    }
}

Components文件下oneTypeNav.vue代码:

  <div class="one-box">
      <router-link v-for="(item,i) in urls" :key="i" :to="`/typeList/${item}`">{{item}}</router-link>
  </div>
</template>

<script>
import {oneTypeNav} from "../tools/ajax.js"
export default {
    data(){
        return{
            urls:[]
        }
    },
     created() {    
         oneTypeNav().then(res=>{
             this.urls = res.splice(0,9)
         })
     },
}
</script>

<style scoped>
    .one-box{
        display: flex;
        justify-content: space-between;
        width: 1200px;
        margin: auto;
        position: relative;
        padding:10px;
        top: -10px;
    }
    a{
        text-decoration: none;
        color: #666;
        display: inline-block;
        padding: 10px 30px;
        border-radius: 5px;
        transition: all 0.2s;

    }
     a:hover,.router-link-exact-active{
        background: purple;
        color: whitesmoke;
    }
</style>

Components文件下GoodList代码:

  <div class="goods-box">
    <router-link
      :to="`/detail?gId=${good.Id}`"
      v-for="(good, i) in list"
      :key="i"
    >
      //拼接字符串'"/detail?gId="+good.Id'
      <img v-lazy="good.imageUrl" alt="" />
      <h4 class="title">{{ good.title }}</h4>
      <p>
        <span class="price">¥{{ good.priceStr }}</span>
        <span class="mack" v-html="good.mack"></span>
      </p>
    </router-link>
  </div>
</template>

<script>
export default {
  props: ["list"],
};
</script>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
<style scoped>
.goods-box {
  width: 1100px;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
}
.goods-box::after {
  content: "";
  flex: 1;
}
a {
  width: 200px;
  height: 220px;
  border: 1px solid lightgray;
  box-sizing: border-box;
  margin-top: 20px;
  margin-left: 20px;
  text-decoration: none;
}
img {
  width: 160px;
  height: 160px;
}
.price {
  text-align: left;
  float: left;
  position: relative;
  top: 10px;
  color: red;
}
.mack {
  float: right;
  position: relative;
  top: 10px;
}
.title {
  text-align: left;
  color: black;
  font-size: 15px;
  position: relative;
  left: 5px;
}
.mack >>> span {
  padding: 5px;
}
</style>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值