vant怎么实现Collapse折叠面板标题自定义

这篇文章主要介绍了vant怎么实现Collapse折叠面板标题自定义的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇vant怎么实现Collapse折叠面板标题自定义文章都会有所收获,下面我们一起来看看吧。

vant Collapse折叠面板标题自定义

vue-cli3+vant实现折叠面板上面标题自定义

代码如下:

<van-collapse v-model="activeNames">
    <van-collapse-item name="1">
        <template slot="title">
 
//以下内容根据需求填充
 
          <div class="title-box">
            <div class="title-box-top">
              <div>
                粤A2323
              </div>
              <div>¥23.32</div>
            </div>
            <div class="number">53454325432</div>
          </div>
        </template>
    </van-collapse-item>
</van-collapse>

使用vant折叠面板自定义内容

效果图:

vant怎么实现Collapse折叠面板标题自定义  vant 第1张

Collapse 折叠面板

介绍

将一组内容放置在多个折叠面板中,点击面板的标题可以展开或收缩其内容。

引入

import Vue from 'vue';
import { Collapse, CollapseItem } from 'vant';
 
Vue.use(Collapse);
Vue.use(CollapseItem);

代码演示

基础用法

通过 v-model 控制展开的面板列表,activeNames 为数组格式。

<van-collapse v-model="activeNames">
  <van-collapse-item title="标题1" name="1">内容</van-collapse-item>
  <van-collapse-item title="标题2" name="2">内容</van-collapse-item>
  <van-collapse-item title="标题3" name="3">内容</van-collapse-item>
</van-collapse>
export default {
  data() {
    return {
      activeNames: ['1'],
    };
  },
};

在基础用法的基础上,因为页面太长,因此需要使用手风琴模式。

手风琴

通过 accordion 可以设置为手风琴模式,最多展开一个面板,此时 activeName 为字符串格式。

<van-collapse v-model="activeName" accordion>
  <van-collapse-item title="标题1" name="1">内容</van-collapse-item>
  <van-collapse-item title="标题2" name="2">内容</van-collapse-item>
  <van-collapse-item title="标题3" name="3">内容</van-collapse-item>
</van-collapse>
export default {
  data() {
    return {
      activeName: '1',
    };
  },
};

基于以上官方文档介绍,下面实现自己的代码逻辑。

 页面渲染:

<van-collapse v-model="activeNames" accordion>
                    <van-collapse-item :title="item.type" :name="item.type" v-for="        (item,index) in typelist" :key="index">
                        <van-form v-for="(ele,i) in item.data" :key="i">
                            <van-row gutter="20">
                                <van-col span="2">
                                    <van-field
                                        :name="i+1+''"
                                        :label="i+1"
                                    />
                                </van-col>
                                <van-col span="16">
                                    <van-field
                                        v-model="ele.name"
                                        label-width="16em"
                                        :name="ele.name"
                                        :label="ele.name"
                                    />
                                </van-col>
                                <van-col span="6">
                                    <van-field
                                        v-model="ele.unit"
                                        :name="ele.unit"
                                        :label="'单位:'+ele.unit"
                                    />
                                </van-col>
                                <van-field 
                                        type="digit"
                                        v-model="ele.xiaohao"
                                        name="消耗数量"
                                        label="消耗数量"
                                    />
                                    <van-field
                                        type="digit"
                                        v-model="ele.kucun"
                                        name="库存数量"
                                        label="库存数量"
                                    />
                                    <van-field 
                                        type="digit"
                                        v-model="ele.waigou"
                                        name="外部购"
                                        label="外部购(新增数量)"
                                    />
                                    <van-field 
                                        type="digit"
                                        v-model="ele.shangdiao"
                                        name="上面调"
                                        label="上面调(新增数量)"
                                    />
                                    <van-field 
                                        type="digit"
                                        v-model="ele.juan"
                                        name="各方捐"
                                        label="各方捐(新增数量)"
                                    />
                                    <van-field
                                        type="textarea"
                                        v-model="ele.beizhu"
                                        name="备注"
                                        label="备注"
                                    />
                            </van-row>
                        </van-form>
                    </van-collapse-item>
                </van-collapse>

数据准备:

typelist:[
    {
        type:"医疗设备",
        data:[
            {name: "手持式红外线测温仪",name_id: "21",type: "医疗设备",type_id: "104"},
            {name: "手持式红外线测温仪",name_id: "21",type: "医疗设备",type_id: "104"},
            {name: "手持式红外线测温仪",name_id: "21",type: "医疗设备",type_id: "104"},
            {name: "手持式红外线测温仪",name_id: "21",type: "医疗设备",type_id: "104"}
        ]
    },
    {
        type:"医疗设备1",
        data:[
            {name: "手持式红外线测温仪",name_id: "21",type: "医疗设备1",type_id: "105"},
            {name: "手持式红外线测温仪",name_id: "21",type: "医疗设备1",type_id: "105"}
        ]
    }   
]

关于“vant怎么实现Collapse折叠面板标题自定义”这篇文章的内容就介绍到这里,感谢各位的阅读!相信大家对“vant怎么实现Collapse折叠面板标题自定义”知识都有一定的了解,大家如果还想学习更多知识,欢迎关注蜗牛博客行业资讯频道。

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:niceseo99@gmail.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

评论

有免费节点资源,我们会通知你!加入纸飞机订阅群

×
天气预报查看日历分享网页手机扫码留言评论Telegram