list.vue 2.36 KB
<template>
    <div class="goods-box">
        <ul class="cardlist card-large">
            <li class="card" v-for="item in items">
                <div class="card-pic">
                    <a href="">
                        <img :src="item.img" alt="{{item.name}}">
                    </a>
                </div>
                <div class="card-bd">
                    <h2 class="card-label">
                        <a href="">{{item.label}}</a>
                    </h2>
                    <span class="good-price" :class="{'old-price': item.market_price}" v-if="item.market_price">¥ {{item.market_price}}</span>
                    <span class="good-price" :class="{'sale-price': item.market_price}">¥ {{item.sale_price}}</span>
                </div>
            </li>
        </ul>
    </div>
</template>
<script>
let $ = require('yoho-jquery');

module.exports = {
    props: {
        //请求 地址
        url: {
            type: String,
            required: true
        },
        //请求参数
        query: Object
    },
    data: function() {
        return {
            items: []
        }
    },
    methods: {
        fetch: function() {
            $.ajax({
                url: this.url,
                type: 'POST',
            })
            .then(data=>{
                console.log(data)
            })
        }
    },
    ready: function() {
        this.fetch()
    },

}
</script>
<style>
@import '../../scss/common/color';
.cardlist {
    list-style: none;
    margin: 0;
    padding: 0;
}

.card-large {
    .card {
        float: left;
        width: 372px;
        margin-right: 6px;
        &:nth-child(2n) {
            margin-right: 0;
        }
        ;
    }
    .card-pic {
        width: 100%;
        height: 499px;
        a,
        img {
            display: block;
            width: 100%;
            height: 100%;
        }
    }
    .card-bd {
        min-height: 180px;
        margin-left: 30px;
        margin-right: 30px;
        padding-top: 25px;
        text-align: center;
        font-size: 24px;
    }
    .card-label {
        margin: 0 0 10px 0;
        font-size: inherit;
        font-weight: normal;
    }
}

.good-price {
    color: #b0b0b0;
    margin-right: 10px;
    &:last-of-type {
        margin-right: 0;
    }
    &.old-price {
        text-decoration: line-through;
    }
    &.sale-price {
        color: $red;
    }
}
</style>