Vue 购物车案例 黑马学院

本文详细介绍了如何使用Vue.js创建一个购物车应用,包括项目初始化、组件划分、数据获取、商品展示、选中状态控制、数量增减、全选功能、总数量与总价计算等关键步骤,提供完整的代码示例。
摘要由CSDN通过智能技术生成

项目初始化:

需求1:从0新建项目

需求2:分拆组件,创建组件文件

分析:

①:vue命令创建项目(在根目录下运行)

vue create shopcar-deom

②:下载需要得配置:

yarn add less less-loader bootstrap

③:main.js - 引入bootst 样式

// 直接引入 bootstrap 的css文件样式
import 'bootstrap/dist/css/bootstrap.css'

补充:下载时候可能会因为网络出问题

//查看当前源
yarn config get registry
//设置淘宝源或内网源
yarn config set registry https://registry.npm.taobao.org --global
//恢复源
yarn config set registry https://registry.yarnpkg.com --global

准备代码:

MyHeader:

<template>
  <div class="my-header">购物车案例</div>
</template>

<script>
export default {}
</script>

<style lang="less" scoped>
.my-header {
     
  height: 45px;
  line-height: 45px;
  text-align: center;
  background-color: #1d7bff;
  color: #fff;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  z-index: 2;
}
</style>

MyGoods:

<template>
  <div class="my-goods-item">
    <div class="left">
      <div class="custom-control custom-checkbox">
        <input type="checkbox" class="custom-control-input" id="input">
        <label class="custom-control-label" for="input">
          <img src="http://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg" alt="">
        </label>
      </div>
    </div>
    <div class="right">
      <div class="top">商品名字</div>
      <div class="bottom">
        <span class="price">¥ 100</span>
        <span>
          <MyCount></MyCount>
        </span>
      </div>

    </div>
  </div
  • 1
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

编程武六七

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值