在现代城市生活中,交通卡已成为人们日常出行必不可少的工具。为了满足用户便捷查询余额、交易记录和进行充值等需求,本文将介绍如何使用 Vue.js 实现一个交通卡功能。
本代码实现了以下功能:
const app = createApp({
// ...
});
TransportCard 组件:
<van-card
class="bg-blue-100 text-blue-500 border-blue-300"
title="Mini Metro"
thumb="https://source.unsplash.com/random/100x100"
>
<template #footer>
<div class="flex justify-between">
<div>Bakerloo Tube Station</div>
<div>£4.50</div>
</div>
</template>
</van-card>
#footer
插槽用于自定义卡片底部内容,显示交易详情。const active = ref(0);
const historyList = [
// ...
];
active
变量用于控制底部导航栏的激活状态。historyList
数组存储了最近的交易记录。充值按钮点击事件:
<van-button
round
type="primary"
size="large"
class="bg-orange-500 text-white"
>
Top Up
</van-button>
<van-tabbar
:active="active"
:model-value="active"
:safe-area-inset-bottom="false"
>
<van-tabbar-item icon="home-o" to="/home">Home</van-tabbar-item>
<van-tabbar-item icon="message-o" to="/message">Message</van-tabbar-item>
<van-tabbar-item icon="contact-o" to="/contact">Contact</van-tabbar-item>
<van-tabbar-item icon="me-o" to="/me">Me</van-tabbar-item>
</van-tabbar>
开发过程中的经验与收获:
未来该卡片功能的拓展与优化: