当前位置:首页 > uni-app

uniapp卡片代码

2026-02-06 05:00:16uni-app

以下是一些常用的UniApp卡片样式代码示例,可根据需求调整样式和功能:

uniapp卡片代码

基础卡片布局

使用viewcss实现基础卡片效果:

uniapp卡片代码

<template>
  <view class="card">
    <view class="card-header">标题</view>
    <view class="card-body">
      这里是卡片内容区域
    </view>
    <view class="card-footer">
      <button size="mini">操作按钮</button>
    </view>
  </view>
</template>

<style>
.card {
  margin: 15px;
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.1);
  overflow: hidden;
}
.card-header {
  padding: 12px;
  background-color: #f7f7f7;
  font-weight: bold;
}
.card-body {
  padding: 15px;
}
.card-footer {
  padding: 10px;
  text-align: right;
  border-top: 1px solid #eee;
}
</style>

带图片的卡片

<template>
  <view class="image-card">
    <image src="/static/example.jpg" mode="aspectFill" class="card-image"></image>
    <view class="card-content">
      <text class="card-title">图片标题</text>
      <text class="card-desc">这里是图片描述文字</text>
    </view>
  </view>
</template>

<style>
.image-card {
  width: 90%;
  margin: 15px auto;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 3px 12px rgba(0,0,0,0.1);
}
.card-image {
  width: 100%;
  height: 180px;
}
.card-content {
  padding: 12px;
}
.card-title {
  font-size: 16px;
  font-weight: bold;
  margin-bottom: 5px;
}
.card-desc {
  font-size: 14px;
  color: #666;
}
</style>

商品卡片示例

<template>
  <view class="goods-card" @click="handleClick">
    <image :src="goodsData.image" class="goods-image"></image>
    <view class="goods-info">
      <text class="goods-title">{{goodsData.title}}</text>
      <view class="price-section">
        <text class="goods-price">¥{{goodsData.price}}</text>
        <text class="goods-origin-price">¥{{goodsData.originPrice}}</text>
      </view>
      <text class="goods-sales">已售{{goodsData.sales}}件</text>
    </view>
  </view>
</template>

<script>
export default {
  props: {
    goodsData: {
      type: Object,
      default: () => ({
        image: '/static/goods-example.jpg',
        title: '商品名称',
        price: 99,
        originPrice: 129,
        sales: 100
      })
    }
  },
  methods: {
    handleClick() {
      uni.navigateTo({
        url: '/pages/goods/detail?id=' + this.goodsData.id
      });
    }
  }
}
</script>

<style>
.goods-card {
  width: 48%;
  display: inline-block;
  margin: 1%;
  background: #fff;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 1px 5px rgba(0,0,0,0.05);
}
.goods-image {
  width: 100%;
  height: 160px;
}
.goods-info {
  padding: 8px;
}
.goods-title {
  font-size: 14px;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
}
.price-section {
  margin-top: 5px;
}
.goods-price {
  color: #f44;
  font-size: 16px;
  font-weight: bold;
}
.goods-origin-price {
  color: #999;
  font-size: 12px;
  text-decoration: line-through;
  margin-left: 5px;
}
.goods-sales {
  display: block;
  font-size: 12px;
  color: #999;
  margin-top: 3px;
}
</style>

卡片滑动组件

实现横向滚动的卡片列表:

<template>
  <scroll-view scroll-x class="card-scroll">
    <view class="scroll-card" v-for="(item,index) in cardList" :key="index">
      <image :src="item.image" class="scroll-card-image"></image>
      <text class="scroll-card-title">{{item.title}}</text>
    </view>
  </scroll-view>
</template>

<style>
.card-scroll {
  white-space: nowrap;
  padding: 10px 0;
}
.scroll-card {
  width: 120px;
  display: inline-block;
  margin-right: 10px;
  background: #fff;
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.scroll-card-image {
  width: 120px;
  height: 80px;
}
.scroll-card-title {
  display: block;
  padding: 8px;
  font-size: 12px;
  white-space: normal;
}
</style>

以上代码示例涵盖了常见的卡片样式需求,可根据实际项目需要进行调整和组合使用。

标签: 卡片代码
分享给朋友:

相关文章

vue 实现代码

vue 实现代码

Vue 是一个流行的前端框架,用于构建用户界面。以下是一个简单的 Vue 实现代码示例,展示如何创建一个基本的 Vue 应用。 安装 Vue 通过 CDN 引入 Vue: <script s…

vue实现登录代码

vue实现登录代码

以下是一个基于 Vue.js 的登录功能实现示例,包含表单验证和异步请求处理: 基础组件结构 <template> <div class="login-container"&g…

vue实现卡片拖动

vue实现卡片拖动

Vue 实现卡片拖动的几种方法 使用 HTML5 拖放 API HTML5 提供了原生的拖放 API,可以在 Vue 中直接使用。通过 draggable 属性标记可拖动的元素,并监听 dragsta…

vue实现商品卡片

vue实现商品卡片

Vue 实现商品卡片 在 Vue 中实现商品卡片可以通过组件化的方式完成,以下是一个完整的实现方案: 商品卡片组件 <template> <div class="product…

vue代码框实现

vue代码框实现

Vue 代码框实现方法 在 Vue 中实现代码框功能通常需要结合语法高亮库或 UI 组件库。以下是几种常见实现方式: 使用第三方库 Prism.js 安装 Prism.js 及相关依赖: npm…

vue实现卡片切换

vue实现卡片切换

Vue实现卡片切换的方法 使用v-if和v-show指令 通过Vue的指令控制卡片的显示与隐藏,适合简单的卡片切换需求。 <template> <div> <…