产品列表-

1. 布局相同的产品列表可以封装组件  采用插槽进行不同的渲染

2. 相同的商品小卡片也可以单独封装组件  以便复用

<script setup>
defineProps({
  goods: {
    type: Object,
    default: () => { }
  }
})
</script>

<template>
  <RouterLink to="/" class="goods-item">
    <img :src="goods.picture" alt="" />
    <p class="name ellipsis">{{ goods.name }}</p>
    <p class="desc ellipsis">{{ goods.desc }}</p>
    <p class="price">&yen;{{ goods.price }}</p>
  </RouterLink>
</template>


<style scoped lang="scss">
.goods-item {
  display: block;
  width: 220px;
  padding: 20px 30px;
  text-align: center;
  transition: all .5s;

  &:hover {
    transform: translate3d(0, -3px, 0);
    box-shadow: 0 3px 8px rgb(0 0 0 / 20%);
  }

  img {
    width: 160px;
    height: 160px;
  }

  p {
    padding-top: 10px;
  }

  .name {
    font-size: 16px;
  }

  .desc {
    color: #999;
    height: 29px;
  }

  .price {
    color: $priceColor;
    font-size: 20px;
  }
}
</style>

3. 封装后使用

使用时传入一个数据  

<ul class="goods-list">
  <li v-for="goods in cate.goods" :key="item.id">
    <GoodsItem :goods="goods" />
  </li>
</ul>

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,这是一个比较简单的产品信息管理模块,可以使用C++中的类和对象来实现。下面是一个简单的实现,仅供参考: ```c++ #include <iostream> #include <string> #include <vector> using namespace std; // 产品信息类 class Product { public: string name; // 产品名称 string model; // 产品规格型号 string desc; // 产品描述 double price; // 产品价格 // 构造函数 Product() {} // 构造函数,用于快速初始化产品信息 Product(string name, string model, string desc, double price) { this->name = name; this->model = model; this->desc = desc; this->price = price; } // 显示产品信息 void display() { cout << "产品名称:" << name << endl; cout << "规格型号:" << model << endl; cout << "产品描述:" << desc << endl; cout << "产品价格:" << price << endl; } }; // 产品管理类 class ProductManager { private: vector<Product> products; // 产品列表 public: // 添加产品信息 void addProduct(Product product) { products.push_back(product); cout << "添加成功!" << endl; } // 修改产品信息 void modifyProduct(string name, string model, Product newProduct) { for (int i = 0; i < products.size(); i++) { if (products[i].name == name && products[i].model == model) { products[i] = newProduct; cout << "修改成功!" << endl; return; } } cout << "未找到该产品!" << endl; } // 删除产品信息 void deleteProduct(string name, string model) { for (int i = 0; i < products.size(); i++) { if (products[i].name == name && products[i].model == model) { products.erase(products.begin() + i); cout << "删除成功!" << endl; return; } } cout << "未找到该产品!" << endl; } // 查询所有产品信息 void queryAll() { if (products.size() == 0) { cout << "暂无产品信息!" << endl; return; } for (int i = 0; i < products.size(); i++) { cout << "===========" << endl; products[i].display(); } } // 按产品名称查询 void queryByName(string name) { vector<Product> result; for (int i = 0; i < products.size(); i++) { if (products[i].name == name) { result.push_back(products[i]); } } if (result.size() == 0) { cout << "未找到该产品!" << endl; return; } for (int i = 0; i < result.size(); i++) { cout << "===========" << endl; result[i].display(); } } // 按产品规格型号查询 void queryByModel(string model) { vector<Product> result; for (int i = 0; i < products.size(); i++) { if (products[i].model == model) { result.push_back(products[i]); } } if (result.size() == 0) { cout << "未找到该产品!" << endl; return; } for (int i = 0; i < result.size(); i++) { cout << "===========" << endl; result[i].display(); } } }; int main() { ProductManager manager; while (true) { cout << "请选择操作:1.添加产品信息 2.修改产品信息 3.删除产品信息 4.查询所有产品信息 5.按名称查询 6.按规格型号查询 0.退出" << endl; int choice; cin >> choice; if (choice == 0) { break; } else if (choice == 1) { cout << "请输入产品名称:"; string name; cin >> name; cout << "请输入产品规格型号:"; string model; cin >> model; cout << "请输入产品描述:"; string desc; cin >> desc; cout << "请输入产品价格:"; double price; cin >> price; Product product(name, model, desc, price); manager.addProduct(product); } else if (choice == 2) { cout << "请输入要修改的产品名称和规格型号:"; string name, model; cin >> name >> model; cout << "请输入新的产品信息:"; string newName, newModel, newDesc; double newPrice; cout << "请输入产品名称:"; cin >> newName; cout << "请输入产品规格型号:"; cin >> newModel; cout << "请输入产品描述:"; cin >> newDesc; cout << "请输入产品价格:"; cin >> newPrice; Product newProduct(newName, newModel, newDesc, newPrice); manager.modifyProduct(name, model, newProduct); } else if (choice == 3) { cout << "请输入要删除的产品名称和规格型号:"; string name, model; cin >> name >> model; manager.deleteProduct(name, model); } else if (choice == 4) { manager.queryAll(); } else if (choice == 5) { cout << "请输入要查询的产品名称:"; string name; cin >> name; manager.queryByName(name); } else if (choice == 6) { cout << "请输入要查询的产品规格型号:"; string model; cin >> model; manager.queryByModel(model); } else { cout << "无效操作!" << endl; } } return 0; } ``` 这个程序中,我们定义了一个 `Product` 类来表示产品信息,其中包含了产品名称、规格型号、描述和价格等属性。然后,我们又定义了一个 `ProductManager` 类来管理产品信息,其中包含了添加、修改、删除和查询等方法。 在 `main` 函数中,我们使用一个循环来不断读取用户的选择,然后调用对应的方法来处理。例如,当用户选择添加产品信息时,我们就会提示用户输入产品的各种属性,然后创建一个 `Product` 对象,并调用 `ProductManager` 的 `addProduct` 方法将其添加到产品列表中。其他操作也类似。 需要注意的是,这个程序还有一些不足之处,例如没有进行输入验证、没有进行异常处理等等。这些问题需要根据具体情况进行完善。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值