前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >uni-app点击按钮,生成列表元素

uni-app点击按钮,生成列表元素

作者头像
王小婷
发布2020-02-11 16:10:57
2.5K0
发布2020-02-11 16:10:57
举报
文章被收录于专栏:编程微刊编程微刊编程微刊

在jQuery里面,动态生成div元素需要进行html的拼接,拼接完成再将拼接的内容放到指定的div里面去,在vue中一般编写代码时都不需要操作DOM元素,那么点击按钮的时候,怎么动态生成自己想要的列表元素?

其实很简单:示例代码如下

<template>
    <view class="content">
        <view class="cu-card case" v-for="(item,index) in productList" :key="index">
            <view class="cu-item shadow">
                <view class="cu-list menu-avatar">
                    <view class="cu-item">
                        <view class="cu-avatar round lg" style="background-image:url(https://ossweb-img.qq.com/images/lol/web201310/skin/big10006.jpg);"></view>
                        <view class="content flex-sub">
                            <view class="text-grey">打卡时间:{{item.beginTime}}</view>
                            <view class="text-gray text-sm flex justify-between">
                                <text class="cuIcon-locationfill margin-lr-xs">{{item.name}}</text>
                                <view class="text-gray text-sm">
                                    <text class="cuIcon-messagefill margin-lr-xs"></text> {{item.stats}}
                                </view>
                            </view>
                        </view>
                    </view>
                </view>
            </view>
        </view>
        <view class="cardcont">
            <view class="circle" @click="clickTest">上班打卡</view>
        </view>
    </view>
</template>

<script>
    export default {
        data() {
            return {        
                productList: [{
                    image: 'https://img-cdn-qiniu.dcloud.net.cn/uploads/example/product1.jpg',
                    name: '光大会展',
                    date: '2019-12-31',
                    beginTime: '2019-12-31   9:30',
                    endTime: '2019-12-31   9:30',
                    total: '3小时',
                    stats: '正常'
                }],
            }
        },
        onLoad() {
        },
        methods: {
            clickTest: function(e) {
                console.log(e);
                console.log('click');
                let listcard = {
                    image: 'https://img-cdn-qiniu.dcloud.net.cn/uploads/example/product1.jpg',
                    name: '光大会展',
                    date: '2019-12-31',
                    beginTime: '2019-12-31   9:30',
                    endTime: '2019-12-31   9:30',
                    total: '3小时',
                    stats: '正常'
                }
                this.productList.push(listcard)
            },
        }
    }
</script>
<style>
    .cu-card>.cu-item {
        margin: 10px 14px 0px 14px;
    }
    .cu-list.menu-avatar>.cu-item {
        height: 87px;
    }
    .title {
        color: #8f8f94;
        margin-top: 50upx;
    }
    .ul {
        font-size: 30upx;
        color: #8f8f94;
        margin-top: 50upx;
    }
    .ul>view {
        line-height: 50upx;
    }
    /* 主要内容 */
    .uni-list-cell {
        border: 1px solid #f0f0f0;
        margin: 10upx 20upx;
    }
    .cardcont {
        position: absolute;
        bottom: 12px;
        left: 35%;
    }
    .circle {
        width: 80px;
        height: 80px;
        line-height: 80px;
        border-radius: 50%;
        text-align: center;
        background-image: linear-gradient(to bottom, lightblue, darkblue);
        font-size: 17px;
        color: #ffffff;
    }
</style>
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档