简体   繁体   English

Ant 设计 Vue - 折叠组件中的自定义 Header

[英]Ant Design Vue - Custom Header in Collapse Component

Hello I'am using Vue and Ant Design.您好,我正在使用 Vue 和 Ant 设计。 So i pick Collapse Component from Ant Design: https://antdv.com/components/collapse/ My problem is that in Collapse.Panel there is a prop header which is string , but i need to put string in there (example: v0.6.1.11) and date, so i can add margin-left: auto or something like that in date. So i pick Collapse Component from Ant Design: https://antdv.com/components/collapse/ My problem is that in Collapse.Panel there is a prop header which is string , but i need to put string in there (example: v0 .6.1.11) 和日期,所以我可以在日期中添加margin-left: auto或类似的东西。 Exmaple:示例:

在此处输入图像描述

I tried using white-space: pre and then simply add spaces to achive that space between but it's not responsive solution.我尝试使用white-space: pre然后简单地添加空格以实现该空间,但它不是响应式解决方案。

How can i pass into header prop pure html so i could put something like two <p> tags there and then create space between title and date?我怎样才能传入 header 道具纯 html 所以我可以在那里放两个<p>标签,然后在标题和日期之间创建空格?

As per docs , we can make use of Panel property extra slot.根据文档,我们可以使用 Panel 属性extra插槽。

Run this sample code运行此示例代码

 new Vue({ el: "#app", data() { return { text: `A dog is a type of domesticated animal.Known for its loyalty and faithfulness,it can be found as a welcome guest in many households across the world.`, activeKey: ['1'], expandIconPosition: 'left', }; }, computed:{ currDate(){ return new Date().toLocaleDateString() } } });
 .ant-collapse>.ant-collapse-item>.ant-collapse-header{ display:flex; justify-content:space-between }
 <link rel="stylesheet" href="https://unpkg.com/ant-design-vue@1.4.11/dist/antd.min.css"> <script src="https://unpkg.com/vue@2.6.11/dist/vue.min.js"></script> <script src="http://bms.test/vendor/laravel-admin/moment/min/moment-with-locales.min.js"></script> <script src="https://unpkg.com/ant-design-vue@1.5.0/dist/antd.min.js"></script> <div id="app"> <a-collapse v-model="activeKey"> <a-collapse-panel key="1" header="This is panel header 1"> <p>{{ text }}</p> <div slot="extra">{{currDate}}</div> </a-collapse-panel> <a-collapse-panel key="2" header="This is panel header 2":disabled="false"> <p>{{ text }}</p> <div slot="extra">{{currDate}}</div> </a-collapse-panel> <a-collapse-panel key="3" header="This is panel header 3" disabled> <p>{{ text }}</p> <div slot="extra">{{currDate}}</div> </a-collapse-panel> </a-collapse> </div>

You can use the below code for the pupose.您可以为此目的使用以下代码。

 <a-collapse-panel key="1" header="heading 1">
        <p>Content</p>
        <template #extra><p>heading 2</p></template> <!-- for newer version -->
        <p slot="extra">heading 2</p> <!-- for older version -->
  </a-collapse-panel>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM