欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 汽车 > 维修 > vue模拟扑克效果

vue模拟扑克效果

2025/4/19 15:16:46 来源:https://blog.csdn.net/cf8833/article/details/147157513  浏览:    关键词:vue模拟扑克效果

vue模拟扑克效果

效果图:
在这里插入图片描述

step1:C:\Users\wangrusheng\PycharmProjects\untitled18\src\views\Home.vue

<template><div class="poker-container"><!-- 使用复合数据对象实现双行显示 --><divv-for="(card, index) in POKER_CARDS":key="index"class="poker-card":class="[cardColors(card.suit), { 'joker-card': card.type === 'JOKER' }]"><template v-if="card.type === 'JOKER'"><!-- 修改后的JOKER结构 --><div class="card-top">{{ card.size === 'little' ? '🦈' : '🐬' }}</div><div class="card-center" :class="card.size === 'big' ? 'red-text' : 'gray-text'">JOKER</div><div class="card-bottom">{{ card.size === 'little' ? '🦈' : '🐬' }}</div></template><template v-else><div class="card-top">{{ card.suit }}</div><div class="card-center">{{ card.number }}</div><div class="card-bottom">{{ card.suit }}</div></template></div></div>
</template><script>
export default {data() {return {POKER_CARDS: [{ type: 'JOKER', size: 'big' },    // 大王{ type: 'JOKER', size: 'little' }, // 新增的小王{ suit: '♠', number: '2' },{ suit: '♣', number: '2' },{ suit: '♥', number: 'A' },{ suit: '♦', number: 'A' },{ suit: '♠', number: 'A' },{ suit: '♥', number: 'K' },{ suit: '♣', number: 'K' },{ suit: '♠', number: 'K' },{ suit: '♦', number: '10' },{ suit: '♠', number: '10' },{ suit: '♥', number: '8' },{ suit: '♦', number: '8' },{ suit: '♥', number: '8' },{ suit: '♠', number: '8' },{ suit: '♦', number: '4' }]}},methods: {cardColors(suit) {return {'black-text': ['♠', '♣'].includes(suit),'red-text': ['♥', '♦'].includes(suit)}}}
}
</script><style>
.poker-container {display: flex;gap: 12px;padding: 20px;background: white;flex-wrap: wrap;justify-content: center;
}.poker-card {width: 80px;height: 120px;border: 1px solid #ddd;border-radius: 8px;display: flex;flex-direction: column;justify-content: space-between;padding: 8px;box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}.black-text { color: #333; }
.red-text { color: #c00; }.card-top, .card-bottom {font-size: 1.2em;transform: scaleY(0.8);
}.card-center {font-size: 1.8em;font-weight: bold;text-align: center;
}.card-bottom {transform: rotate(180deg);
}
/* 新增灰色文本样式 */
.gray-text { color: #666; }/* 保持JOKER文字与普通卡片一致 */
.joker-card .card-center {font-size:22px;font-weight: bold;text-align: center;/* 通过缩放保持原有布局效果 */transform: scaleY(0.8);
}</style>

end

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词