Vue项目小米购物车

1.vue小米购物车用到了 Vuex + localstorage,使用了vue2,创建项目用vue create xiaomi (名字)1.在Home.vue里面写<template> <div class="home"> <header> <span >首页</span> <router-link to="/about" class="span">购物车({{total...
摘要由CSDN通过智能技术生成

 1.vue小米购物车用到了 Vuex + localstorage,使用了vue2,创建项目用vue create xiaomi (名字)

 

 1.在Home.vue里面写

<template>
  <div class="home">
    <header>
      <span >首页</span>
    <router-link to="/about" class="span">购物车({
  {total}})</router-link>
    </header>
    <div class="list" v-for="item in list" :key="item.id">
    	<div class="left">
    		<img data-v-3ebe9018="" :src="item.img">
    	</div>
    	<div class="right">
    		<h3 class="title">{
  {item.name}}</h3>
    	<p class="slogan">{
  {item.slogan}}</p>
    	<p class="money">{
  {item.price}}</p>
    	<button class="button" @click="setShippingjiajian(item,'PLUS')">加入购物车</button>
    	</div>
    </div>
  </div>
</template>

<script>
import {mapState,mapGetters} from "vuex"

export default {
  name: 'Home',
  computed:{
    ...mapState(["list"]),
    ...mapGetters(["total"])
  },
  created(){
    this.$store.dispatch("setList")
  },
  methods:{
    setShippingjiajian(item,_type){
      console.log(item)
      this.$store.dispatch("setShippingjiajian",{
               id:item.id,
                name:item.name,
                price:item.price,
                img:item.img,
                slogan:item.slogan,
                // 这个_type是定义加减的
                _type
      })
    }
  }
}
</script>
<style scoped>
	.home{
		width: 100%;
	}
header{
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 0.44rem;
  background: #ff6704;
  color: #fff;
  font-size: 0.18rem;
  display: fixed;
}
.span{
  position: absolute;
    right: 0.15rem;
    top: 0.15rem;
    font-size: 0.14rem;
}
.list{
	border-bottom: 1px solid #ddd;
  background: #fff;
	display: flex;
	flex-direction: row;
}
.left img{
	width: 0.94rem;
	height: 0.94rem;
}
.right{
	  flex: 1;
    overflow: hidden;
    height: 1.2rem;
    padding: 0.1rem 0.1rem 0.1rem 0.13rem;
    box-sizing: border-box;
}
.title{
	    color: #333;
    font-size: 0.16rem;
}
.slogan{
	margin-top: 0.05rem;
    color: #999;
    font-size: 0.12rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.money{
	margin-top: 0.15rem;
    color: #ff6704;
    font-size: 0.14rem;
}
.button{
    float: right;
    width: 0.8rem;
    height: 0.2rem;
    font-size: 0.12rem;
    border: 1px solid #ff6704;
    color: #ff6704;
    border-radius: 0.02rem;
  • 6
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值