当前位置:首页 > 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>

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

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

相关文章

网页表格制作css代码

网页表格制作css代码

基础表格样式 使用CSS为HTML表格添加基础样式,包括边框、间距和背景色: table { width: 100%; border-collapse: collapse; margin…

php实现文件下载代码

php实现文件下载代码

实现文件下载的基本方法 使用PHP实现文件下载的核心是通过设置HTTP头部信息,强制浏览器触发下载行为而非直接显示文件内容。 $file_path = 'path/to/your/file.ext'…

vue实现网站代码

vue实现网站代码

Vue 实现网站代码的基本步骤 安装 Vue.js 通过 npm 或 CDN 引入 Vue.js。使用 npm 安装:npm install vue。或者直接在 HTML 文件中引入 Vue CDN:…

vue实现卡片拖拽

vue实现卡片拖拽

Vue 实现卡片拖拽的方法 使用 HTML5 拖放 API HTML5 提供了原生拖放 API,结合 Vue 可以轻松实现拖拽功能。以下是一个基本实现示例: <template> &…

vue实现卡片拖动

vue实现卡片拖动

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

vue代码实现管理

vue代码实现管理

Vue.js 管理后台实现方案 使用 Vue.js 构建管理后台系统通常涉及路由、状态管理、UI 组件库等核心模块。以下是关键实现方案: 基础框架搭建 安装 Vue CLI 创建项目: npm i…