vue模拟扑克效果

vue模拟扑克效果

效果图:

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

typescript 复制代码
<template>
  <div class="poker-container">
    <!-- 使用复合数据对象实现双行显示 -->
    <div
      v-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

相关推荐
橙光成长12 分钟前
GameScrcpy:不装模拟器,用键鼠手柄和 TypeScript 脚本接管你的安卓手游
android·javascript·typescript·开源·1024程序员节
米米商聊1 小时前
AI 搜群附件,同一份 PDF 占满前三条?按附件 ID 折叠片段
javascript·人工智能
代码小学生&1 小时前
IIS 反向代理配置完整流程
javascript
SEO_juper2 小时前
PHP 站内搜索词分析器:从买家搜的词里,挖出内容缺口
前端·javascript·node.js·json·1024程序员节
徐同保2 小时前
一个 HTML 属性顶替三行 JS:`inert` 的正确用法
前端·javascript·html
zhanlang02172 小时前
1.3 CSS 文本与字体样式:打造极具可读性的排版
前端·css
map_3d_vis3 小时前
百度地图画圆 Circle 和矩形 Rectangle(JSAPI 4.0)
前端·javascript·gis·地图·百度地图
AI开源软件3 小时前
SpringBoot多系统同步:别让“同名数据”变成“同一条数据”
vue.js·spring boot·企业管理·mdm
code2cat4 小时前
Vue与React Native任务验收:断网改了标题,重新联网后该看到什么?
vue.js·react native·react.js
FYKJ_20104 小时前
springboot网上汽车租赁系统93523-计算机毕业设计、课程设计
java·vue.js·spring boot·后端·python·汽车·课程设计