当前位置: 首页 > news >正文

14.Home-新鲜好物和人气推荐实现

新鲜好物实现

1.准备模板

<script setup>import HomePanel from './HomePanel.vue'</script><template><homePanel></HomePanel><!-- 下面是插槽主体内容模版<ul class="goods-list"><li v-for="item in newList" :key="item.id"><RouterLink to="/"><img :src="item.picture" alt="" /><p class="name">{{ item.name }}</p><p class="price">&yen;{{ item.price }}</p></RouterLink></li></ul>-->
</template><style scoped lang='scss'>
.goods-list {display: flex;justify-content: space-between;height: 406px;li {width: 306px;height: 406px;background: #f0f9f4;transition: all .5s;&:hover {transform: translate3d(0, -3px, 0);box-shadow: 0 3px 8px rgb(0 0 0 / 20%);}img {width: 306px;height: 306px;}p {font-size: 22px;padding-top: 12px;text-align: center;text-overflow: ellipsis;overflow: hidden;white-space: nowrap;}.price {color: $priceColor;}}
}
</style>

2.定制props

<script setup>import HomePanel from './HomePanel.vue'</script><template><homePanel title="新鲜好物" sub-title="新鲜出炉 品质靠谱"></HomePanel><!-- 下面是插槽主体内容模版<ul class="goods-list"><li v-for="item in newList" :key="item.id"><RouterLink to="/"><img :src="item.picture" alt="" /><p class="name">{{ item.name }}</p><p class="price">&yen;{{ item.price }}</p></RouterLink></li></ul>-->
</template><style scoped lang='scss'>
.goods-list {display: flex;justify-content: space-between;height: 406px;li {width: 306px;height: 406px;background: #f0f9f4;transition: all .5s;&:hover {transform: translate3d(0, -3px, 0);box-shadow: 0 3px 8px rgb(0 0 0 / 20%);}img {width: 306px;height: 306px;}p {font-size: 22px;padding-top: 12px;text-align: center;text-overflow: ellipsis;overflow: hidden;white-space: nowrap;}.price {color: $priceColor;}}
}
</style>

3.定制接口

/*** @description: 获取新鲜好物* @param {*}* @return {*}*/
export const findNewAPI = () => {return httpInstance({url:'/home/new'})
}
<script setup>import HomePanel from './HomePanel.vue'import {findNewAPI} from '@/apis/home'//获取数据
const newlist = ref([])const getNewList = async() => {const res = await findNewAPI()newList.value = res.result
}onMounted(() => getNewList())
</script><template><homePanel title="新鲜好物" sub-title="新鲜出炉 品质靠谱"></HomePanel><!-- 下面是插槽主体内容模版<ul class="goods-list"><li v-for="item in newList" :key="item.id"><RouterLink to="/"><img :src="item.picture" alt="" /><p class="name">{{ item.name }}</p><p class="price">&yen;{{ item.price }}</p></RouterLink></li></ul>-->
</template><style scoped lang='scss'>
.goods-list {display: flex;justify-content: space-between;height: 406px;li {width: 306px;height: 406px;background: #f0f9f4;transition: all .5s;&:hover {transform: translate3d(0, -3px, 0);box-shadow: 0 3px 8px rgb(0 0 0 / 20%);}img {width: 306px;height: 306px;}p {font-size: 22px;padding-top: 12px;text-align: center;text-overflow: ellipsis;overflow: hidden;white-space: nowrap;}.price {color: $priceColor;}}
}
</style>

4.插槽

<script setup>import HomePanel from './HomePanel.vue'import {findNewAPI} from '@/apis/home'//获取数据
const newlist = ref([])const getNewList = async() => {const res = await findNewAPI()newList.value = res.result
}onMounted(() => getNewList())
</script><template><homePanel title="新鲜好物" sub-title="新鲜出炉 品质靠谱"><ul class="goods-list"><li v-for="item in newList" :key="item.id"><RouterLink to="/"><img v-img-lazy="item.picture"  alt="" /><p class="name">{{ item.name }}</p><p class="price">&yen;{{ item.price }}</p></RouterLink></li></ul></HomePanel>// <!-- 下面是插槽主体内容模版// <ul class="goods-list">//   <li v-for="item in newList" :key="item.id">//     <RouterLink to="/">//       <img :src="item.picture" alt="" />//       <p class="name">{{ item.name }}</p>//       <p class="price">&yen;{{ item.price }}</p>//     </RouterLink>//   </li>// </ul>// -->
</template><style scoped lang='scss'>
.goods-list {display: flex;justify-content: space-between;height: 406px;li {width: 306px;height: 406px;background: #f0f9f4;transition: all .5s;&:hover {transform: translate3d(0, -3px, 0);box-shadow: 0 3px 8px rgb(0 0 0 / 20%);}img {width: 306px;height: 306px;}p {font-size: 22px;padding-top: 12px;text-align: center;text-overflow: ellipsis;overflow: hidden;white-space: nowrap;}.price {color: $priceColor;}}
}
</style>

http://www.xdnf.cn/news/1244665.html

相关文章:

  • 编程算法:技术创新与业务增长的核心引擎
  • Linux操作系统从入门到实战(十三)版本控制器Git基础概念讲解
  • 深入浅出 RabbitMQ-路由模式详解
  • 自由学习记录(77)
  • 24. 前端-js框架-Vue
  • vite面试题及详细答案120题(01-30)
  • 【工程化】tree-shaking 的作用以及配置
  • 研发团队看板协作中的自动化实践:集成CI/CD与任务流转
  • 【Linux系统】进程间通信:基于匿名管道实现进程池
  • linux_https,udp,tcp协议(更新中)
  • C语言基础_随机数、数组、函数、指针
  • 【机器学习深度学习】模型压缩简介
  • C++ - 基于多设计模式下的同步异步日志系统(11w字)
  • NLP——BERT模型全面解析:从基础架构到优化演进
  • AWS EKS节点扩容时NLB与Ingress的故障处理与优化方案
  • LSTM + 自注意力机制:精准预测天气变化的创新方案
  • 深入剖析 RAG 检索系统中的召回方式:BM25、向量召回、混合策略全解析
  • JS-第二十一天-尺寸位置
  • Android UI 组件系列(十一):RecyclerView 多类型布局与数据刷新实战
  • AI 对话高效输入指令攻略(四):AI+Apache ECharts:生成各种专业图表
  • 【学习笔记】Manipulate-Anything(基于视觉-语言模型的机器人自动化操控系统)
  • 【09】C++实战篇——C++ 生成静态库.lib 及 C++调用lib,及实际项目中的使用技巧
  • javacc学习笔记 02、JavaCC 语法描述文件的格式解析
  • Druid手写核心实现案例 实现一个简单Select 解析,包含Lexer、Parser、AstNode
  • k8s常见问题
  • (论文速读)RMT:Retentive+ViT的视觉新骨干
  • 20250805问答课题-实现TextRank + 问题分类
  • 力扣热题100------21.合并两个有序链表
  • 8.高斯混合模型
  • k8s简介