vuex购物车

这是一个使用 Vue 和 Vuex 实现的购物车小型案例。通过 Koa 后台读取 JSON 数据,前端实现了首页渲染、添加购物车、订单管理等功能。主要涉及的文件有 home.js(首页渲染及购物车功能)、shopcar.js(订单添加及其他参数传递)、order.js(订单页面渲染)、mine.js 以及 store 目录下的 index.js、state.js、mutation.js。此外,还封装了 footer.js,并用 data.json 存储数据,Koa 用于后台数据交互。
摘要由CSDN通过智能技术生成

Hi,这个购物车是通过 koa后台读取json数据,前台通过vue,vuex写的前台,小伙伴们主要还是思路要清楚哦,下面先来看看这个小型案例的魔法吧!!!!!

  • home.js
    • 主要写的首页渲染,,以及添加购物车的功能点
<template>
    <div class="home">
        <header>首页</header>
        <section>
              <div class="cont">
                    <dl v-for="(item,index) in data" :key="index">
                        <dt><img :src="item.img" alt=""></dt>
                        <dd>
                            <p class="tit"><span>{
   {
   item.title}}</span><button @click="add(item)">来一份</button></p>
                            <p>{
   {
   item.intro}}</p>
                            <p>{
   {
   item.price}}</p>
                        </dd>
                    </dl>
           </div>
        </section>
      <Footer></Footer>
    </div>
</template>
<script>
import Footer from "../components/footer"
import axios from 'axios'
import {
   mapState,mapMutations} from 'vuex'
export default {
   
    props:{
   

    },
    components:{
   
        Footer,
    },
    data(){
   
        return {
   
            data:[]
        }
    },
    computed:{
   
        ...mapState(['adddata']),
        
    },
    methods:{
   
        ...mapMutations(['changedata']),
        add(adddata){
     //添加进入购物车
            this.$router.push("/shopcar")
            this.$store.commit('changedata',adddata)
        }
    },
    created(){
   
        axios.get('/api').then(res => {
   
            this.data=res.data.message
        })       
    }}
</script>
<style scoped lang="">
  
    .home{
   
        height: 100%;
        width: 100%;
        display: flex;
        flex-direction: column;
    }
    header{
   
        height: 44px;
        width: 100%;
        background: salmon;
        line-height: 44px;
        text-align: center;
    }
    section{
   
        flex:1;
        overflow-y:auto;
    }
 
    .cont dl{
   
        width: 100%;
        display: flex;
        padding: 8px;
    }
    dl dt{
   
        width: 110px;
        height: 110px;
        background: skyblue;
        flex-shrink: 0;
    }
    dl dt img{
   
        height:100%;
        width:100%;
    }
    dl dd{
   
        flex: 1;
        padding-left: 10px;
        line-height: 2.2;
    }
    dl dd .tit{
   
        display: flex;
        justify-content: space-between;
        padding-right: 25px;
    }
    dl dd .tit button{
   
        border: none;
        background: none;
        outline: none;
        color: rgb(6, 196, 202);
        font-size:16px;
    }
</style>
  • shopcar.js
  • 主要的功能是添加订单,以及其他的传参
<template>
    <div class="shopcar">
        <header>购物车</header>
       <section>
            <
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值