前端商城vue项目案例1

在这里插入图片描述
在这里插入图片描述
views/home.vue

<template>
  <div id="home" class="home">
    <van-search v-model="value" placeholder="商品搜索 共239款好物" input-align="center"/>
    <van-swipe :autoplay="3000" style="width:100%;height:200px">
      <van-swipe-item v-for="(image, index) in images" :key="index">
        <img v-lazy="image.image_url" style="width: 100%;height: 200px"/>
      </van-swipe-item>
    </van-swipe>

    <van-grid :column-num="5">
      <van-grid-item v-for="(item,index) in channel" :key="index" :icon="item.url" :text="item.name" />
    </van-grid>
    <div class="brandlist">
      <van-panel title="品牌制造商">
        <van-grid :column-num="2">
          <van-grid-item v-for="(item1,index1) in brandList" :key="index1">
            <img :src="item1.new_pic_url" style="width: 100%; height:100%;display: block"/>
            <h4 class="title">{{item1.name}}</h4>
            <p class="desc">{{item1.floor_price}}元起</p>
          </van-grid-item>
        </van-grid>
      </van-panel>
    </div>
    <div class="newlist">
      <van-panel title="食品好吃货">
        <van-grid :column-num="2">
          <van-grid-item v-for="(item2,index2) in newGoodsList" :key="index2">
            <img :src="item2.list_pic_url" style="width: 100%; height:100%;display: block"/>
            <h4 class="title1">{{item2.name}}</h4>
            <p class="desc1">{{item2.retail_price}}元起</p>
          </van-grid-item>
        </van-grid>
      </van-panel>
    </div>
    <div class="personlist">
      <van-panel title="人气">
        <van-card  v-for="(item3,index3) in hotGoodsList" :key="index3"
                :price="item3.retail_price"
                :desc="item3.goods_brief"
                :title="item3.name"
                :thumb="item3.list_pic_url"
      />
      </van-panel>
    </div>
    <div style="height: 50px"></div>
    <van-tabbar v-model="tabActive">
      <van-tabbar-item icon="wap-home">首页</van-tabbar-item>
      <van-tabbar-item icon="bookmark">分类</van-tabbar-item>
      <van-tabbar-item icon="shopping-cart">购物车</van-tabbar-item>
      <van-tabbar-item icon="column">专题</van-tabbar-item>
      <van-tabbar-item icon="manager">我的</van-tabbar-item>
    </van-tabbar>
  </div>
</template>

<script>
// @ is an alias to /src
import HelloWorld from '@/components/HelloWorld.vue'
import axios from 'axios'
import api from '../assets/config/api'
import Vue from 'vue';
import { Swipe, SwipeItem } from 'vant';
import { Lazyload } from 'vant';
import { Panel } from 'vant';
import { Grid, GridItem } from 'vant';
import { Card } from 'vant'
import { Tabbar, TabbarItem } from 'vant';
Vue.use(Tabbar);
Vue.use(TabbarItem);
Vue.use(Panel);
Vue.use(Card);
Vue.use(Grid);
Vue.use(GridItem);
Vue.use(Swipe);
Vue.use(SwipeItem);


Vue.use(Lazyload);
export default {
  name: 'Home',
  components: {
    HelloWorld
  },
  data(){
    return{
      value:'',
      data:{},
      tabActive:0
    }
  },
  /*将钩子函数的数据放到计算,通过计算方法计算出来*/
  computed:{
    images() {
        if(typeof this.data.banner=='object'){
          return this.data.banner
        }else{
          return []
        }
    },
    channel(){
      if(typeof this.data.channel=='object'){
        return this.data.channel
      }else{
        return []
      }
    },
    brandList(){
      if(typeof this.data.brandList=='object'){
        return this.data.brandList
      }else{
        return []
      }
    },
    newGoodsList(){
      if(typeof this.data.newGoodsList=='object'){
        return this.data.newGoodsList
      }else{
        return []
      }
    },
    hotGoodsList(){
      if(typeof this.data.hotGoodsList=='object'){
        return this.data.hotGoodsList
      }else{
        return []
      }
    }
  },
  async mounted() {
    let res = await axios.get(api.IndexUrl)
    console.log(res.data)
    this.data = res.data.data
  }
}
</script>
<style>
  .brandlist .van-grid-item__content{
      padding: 0px !important;
  }
  .title{
    position: absolute;
    top: 20px;
    left: 10px;
  }
  .desc{
    position: absolute;
    top: 50px;
    left: 10px;
    font-size: 14px;
    color: #999;
  }
  .title1{
      position: absolute;
      bottom: 0;
      width: 90%;
      white-space: nowrap;
      text-overflow:ellipsis;
      overflow: hidden;
  }
  .desc1{
    position: absolute;
    font-size: 14px;
    color: #999;
    bottom: -10px;
  }
  .brandlist img{
    border: 1px solid #fff;
  }
  .personlist .van-card__price{
     color: red !important;
  }

  .personlist .van-card__content{
    text-align:left;
    justify-content: center;
    align-content: center;
  }

  .personlist .van-card__title{
       font-weight: 900;
       color: #333;
       font-size: 14px;
       padding: 5px 0;
  }
</style>

mian.js

import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import { Search } from 'vant';
import 'vant/lib/index.css'
Vue.use(Search);

Vue.config.productionTip = false

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')


版权声明:本文为weixin_42236746原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。