当前位置: 首页 > 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.dtcms.com/a/316744.html

相关文章:

  • 大模型|极简说清“数据并行”
  • 06-队列
  • Crawl4AI:开源的AI友好型网页爬虫与数据抓取工具
  • 电子秤利用Websocket做为Client向MES系统推送数据
  • 软件测试——接口自动化
  • STM32内部读写FLASH
  • 90、【OS】【Nuttx】【启动】栈溢出保护:配置项解析
  • Swift 实战:用队列巧解 LeetCode 346 数据流中的移动平均数
  • 服务器端口连通性的测试工具和方法
  • XXL-JOB调度中心、执行器、Job之间的关系
  • MQTT:消息详解
  • 备忘录记事本 任务清单 html
  • 基于铁头山羊STM32的平衡车电机转速开环闭环matlab仿真
  • 线性规划最优解
  • 饿了么招java开发咯
  • tarjan找SCC,缩点建DAG,找唯一源头节点
  • 强光干扰下误报率↓82%!陌讯多模态融合算法在火焰识别的落地优化
  • 不可变集合
  • nflsoi 7.31 题解
  • 信息化项目验收,项目成功的最后确认
  • Redis中的sdshdr的len和alloc那块的知识点详解
  • 【经验记录贴】在windows系统中启动服务
  • CMU-15445(7)——PROJECT#2-BPlusTree-Task#2Task#3
  • BGA 芯片贴片加工关键注意事项
  • Fiddler 中文版实战指南,如何构建高效的 API 调试工作流?
  • 第13届蓝桥杯Scratch_选拔赛_真题2021年11月27日
  • 老旧体育场馆照明翻新:预算有限?3 步实现 “低成本升级”
  • 在具身智能火热加持下,看 2025 年机器人学术年会中的热点主题。PNP机器人展示力控、灵巧手捕捉等案例。
  • 利用链上数据进行数字资产量化因子发现
  • 计划任务:被忽视的网络与系统安全边界