1. List interface display exampleWhat we need to do now is to style the data entered into the page, that is, to make it look better. Previously, in the article "Vue3 (Part 2) Integrating Ant Design Vue", we mentioned the use of components. For a front-end that is not very good (the back-end is not very good either), in the spirit of "take what you need", the best and most convenient way is to use what we have ready-made. To put it simply, find ready-made components of 1. Choose your favorite list style From As shown in the following figure: 2. Display data2.1. Components are displayed in the list Next, we only need to make changes in The sample code is as follows: <template> <a-layout> <a-layout-sider width="200" style="background: #fff"> <a-menu mode="inline" v-model:selectedKeys="selectedKeys2" v-model:openKeys="openKeys" :style="{ height: '100%', borderRight: 0 }" > <a-sub-menu key="sub1"> <template #title> <span> <user-outlined /> subnav 1 </span> </template> <a-menu-item key="1">option1</a-menu-item> <a-menu-item key="2">option2</a-menu-item> <a-menu-item key="3">option3</a-menu-item> <a-menu-item key="4">option4</a-menu-item> </a-sub-menu> <a-sub-menu key="sub2"> <template #title> <span> <laptop-outlined /> subnav 2 </span> </template> <a-menu-item key="5">option5</a-menu-item> <a-menu-item key="6">option6</a-menu-item> <a-menu-item key="7">option7</a-menu-item> <a-menu-item key="8">option8</a-menu-item> </a-sub-menu> <a-sub-menu key="sub3"> <template #title> <span> <notification-outlined /> subnav 3 </span> </template> <a-menu-item key="9">option9</a-menu-item> <a-menu-item key="10">option10</a-menu-item> <a-menu-item key="11">option11</a-menu-item> <a-menu-item key="12">option12</a-menu-item> </a-sub-menu> </a-menu> </a-layout-sider> <a-list item-layout="vertical" size="large" :pagination="pagination" :data-source="listData"> <template #footer> <div> <b>ant design vue</b> footer part </div> </template> <template #renderItem="{ item }"> <a-list-item key="item.title"> <template #actions> <span v-for="{ type, text } in actions" :key="type"> <component v-bind:is="type" style="margin-right: 8px" /> {{ text }} </span> </template> <template #extra> <img width="272" alt="logo" src="https://gw.alipayobjects.com/zos/rmsportal/mqaQswcyDLcXyDKnZfES.png" /> </template> <a-list-item-meta :description="item.description"> <template #title> <a :href="item.href" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >{{ item.title }}</a> </template> <template #avatar><a-avatar :src="item.avatar" /></template> </a-list-item-meta> {{ item.content }} </a-list-item> </template> </a-list> </a-layout> </template> <script lang="ts"> import { defineComponent,onMounted,ref,reactive,toRef} from 'vue'; import axios from 'axios'; import { StarOutlined, LikeOutlined, MessageOutlined } from '@ant-design/icons-vue'; const listData: Record<string, string>[] = []; for (let i = 0; i < 23; i++) { listData.push({ href: 'https://www.antdv.com/', title: `ant design vue part ${i}`, avatar: 'https://zos.alipayobjects.com/rmsportal/ODTLcjxAfvqbxHnVXCYX.png', description: 'Ant Design, a design language for background applications, is refined by Ant UED Team.', content: 'We supply a series of design principles, practical patterns and high quality design resources (Sketch and Axure), to help people create their product prototypes beautifully and efficiently.', }); } export default defineComponent({ components: StarOutlined, LikeOutlined, MessageOutlined, }, name: 'Home', setup(){ const pagination = { onChange: (page: number) => { console.log(page); }, pageSize: 3, }; const actions: Record<string, string>[] = [ { type: 'StarOutlined', text: '156' }, { type: 'LikeOutlined', text: '156' }, { type: 'MessageOutlined', text: '2' }, ]; console.log('set up'); //Use ref for data binding const ebooks=ref(); // Use reactive data binding const ebooks1 = reactive({books:[]}) onMounted(()=>{ axios.get("http://localhost:8888/ebook/list?name=spring").then(response =>{ console.log("onMounted"); const data=response.data; ebooks.value=data.content; ebooks1.books=data.content; }) }) return { listData, pagination, actions, ebooks1: ebooks, ebooks2:toRef(ebooks1,"books") } } }); </script> Recompile and run to see the effect as follows: 2.2. The data returned by the interface is displayed in a list Obviously now, you can see that the list style you want to use has been successfully displayed on the page, but this is not what I want. What I want is that the data returned by the backend interface is displayed here, that is, the data source. Next, let's adjust the The sample code is as follows: <template> <a-layout> `<a-layout-sider width="200" style="background: #fff"> <a-menu mode="inline" v-model:selectedKeys="selectedKeys2" v-model:openKeys="openKeys" :style="{ height: '100%', borderRight: 0 }" > <a-sub-menu key="sub1"> <template #title> <span> <user-outlined /> subnav 1 </span> </template> <a-menu-item key="1">option1</a-menu-item> <a-menu-item key="2">option2</a-menu-item> <a-menu-item key="3">option3</a-menu-item> <a-menu-item key="4">option4</a-menu-item> </a-sub-menu> <a-sub-menu key="sub2"> <template #title> <span> <laptop-outlined /> subnav 2 </span> </template> <a-menu-item key="5">option5</a-menu-item> <a-menu-item key="6">option6</a-menu-item> <a-menu-item key="7">option7</a-menu-item> <a-menu-item key="8">option8</a-menu-item> </a-sub-menu> <a-sub-menu key="sub3"> <template #title> <span> <notification-outlined /> subnav 3 </span> </template> <a-menu-item key="9">option9</a-menu-item> <a-menu-item key="10">option10</a-menu-item> <a-menu-item key="11">option11</a-menu-item> <a-menu-item key="12">option12</a-menu-item> </a-sub-menu> </a-menu> </a-layout-sider>` <a-list item-layout="vertical" size="large" :pagination="pagination" :data-source="ebooks1"> <template #renderItem="{ item }"> <a-list-item key="item.name"> <template #actions> <span v-for="{ type, text } in actions" :key="type"> <component v-bind:is="type" style="margin-right: 8px" /> {{ text }} </span> </template> <a-list-item-meta :description="item.description"> <template #title> <a :href="item.href" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >{{ item.name }}</a> </template> <template #avatar><a-avatar :src="item.cover" /></template> </a-list-item-meta> </a-list-item> </template> </a-list> </a-layout> </template> <script lang="ts"> import { defineComponent,onMounted,ref,reactive,toRef} from 'vue'; import axios from 'axios'; import { StarOutlined, LikeOutlined, MessageOutlined } from '@ant-design/icons-vue'; const listData: Record<string, string>[] = []; for (let i = 0; i < 23; i++) { listData.push({ href: 'https://www.antdv.com/', title: `ant design vue part ${i}`, avatar: 'https://zos.alipayobjects.com/rmsportal/ODTLcjxAfvqbxHnVXCYX.png', description: 'Ant Design, a design language for background applications, is refined by Ant UED Team.', content: 'We supply a series of design principles, practical patterns and high quality design resources (Sketch and Axure), to help people create their product prototypes beautifully and efficiently.', }); } export default defineComponent({ components: StarOutlined, LikeOutlined, MessageOutlined, }, name: 'Home', setup(){ const pagination = { onChange: (page: number) => { console.log(page); }, pageSize: 3, }; const actions: Record<string, string>[] = [ { type: 'StarOutlined', text: '156' }, { type: 'LikeOutlined', text: '156' }, { type: 'MessageOutlined', text: '2' }, ]; console.log('set up'); //Use ref for data binding const ebooks=ref(); // Use reactive data binding const ebooks1 = reactive({books:[]}) onMounted(()=>{ axios.get("http://localhost:8888/ebook/list?name=spring").then(response =>{ console.log("onMounted"); const data=response.data; ebooks.value=data.content; ebooks1.books=data.content; }) }) return { listData, pagination, actions, ebooks1: ebooks, ebooks2:toRef(ebooks1,"books") } } }); </script> <style> .ant-layout-sider{ float: left; } </style> Recompile and run to see the effect as follows: 2.3 Interface data transformationObviously, the list data is too small, so I modified the interface to return multiple data. From The sample code is as follows: package com.rongrong.wiki.service; import com.rongrong.wiki.domain.EBook; import com.rongrong.wiki.domain.EBookExample; import com.rongrong.wiki.mapper.EBookMapper; import com.rongrong.wiki.req.EBookReq; import com.rongrong.wiki.resp.EBookResp; import org.springframework.stereotype.Service; import org.springframework.util.ObjectUtils; import javax.annotation.Resource; import java.util.List; import static com.rongrong.wiki.util.CopyUtil.copyList; /** * @author rongrong * @version 1.0 * @description * @date 2021/10/13 23:09 */ @Service public class EBookService { @Resource private EBookMapper eBookMapper; public List<EBookResp> list(EBookReq eBookReq) { EBookExample eBookExample = new EBookExample(); //The meaning of the code here is equivalent to creating a Sql where condition EBookExample.Criteria criteria = eBookExample.createCriteria(); //The wavy line indicates that it is not recommended. Let's look at the source code and make a replacement if(!ObjectUtils.isEmpty(eBookReq.getName())){ criteria.andNameLike("%"+eBookReq.getName()+"%"); } List<EBook> eBookList = eBookMapper.selectByExample(eBookExample); //List<EBookResp> eBookRespList = new ArrayList<>(); //for (EBook eBook: eBookList) { // //EBookResp eBookResp = new EBookResp(); // ////Spring boot's own BeanUtils completes the object copy// //BeanUtils.copyProperties(eBook, eBookResp); // //eBookResp.setId(12345L); // //Single copy// EBookResp copy = copy(eBook, EBookResp.class); // eBookRespList.add(copy); //} //List copy List<EBookResp> respList = copyList(eBookList, EBookResp.class); return respList; } } View the data returned by the interface, as follows: 2.4. List displays multiple data in one row The interface modification is completed. Then we need to modify the list display content. Similarly, we find the grid list in the list list. We also modify it in <template> <a-layout> `<a-layout-sider width="200" style="background: #fff"> <a-menu mode="inline" v-model:selectedKeys="selectedKeys2" v-model:openKeys="openKeys" :style="{ height: '100%', borderRight: 0 }" > <a-sub-menu key="sub1"> <template #title> <span> <user-outlined /> subnav 1 </span> </template> <a-menu-item key="1">option1</a-menu-item> <a-menu-item key="2">option2</a-menu-item> <a-menu-item key="3">option3</a-menu-item> <a-menu-item key="4">option4</a-menu-item> </a-sub-menu> <a-sub-menu key="sub2"> <template #title> <span> <laptop-outlined /> subnav 2 </span> </template> <a-menu-item key="5">option5</a-menu-item> <a-menu-item key="6">option6</a-menu-item> <a-menu-item key="7">option7</a-menu-item> <a-menu-item key="8">option8</a-menu-item> </a-sub-menu> <a-sub-menu key="sub3"> <template #title> <span> <notification-outlined /> subnav 3 </span> </template> <a-menu-item key="9">option9</a-menu-item> <a-menu-item key="10">option10</a-menu-item> <a-menu-item key="11">option11</a-menu-item> <a-menu-item key="12">option12</a-menu-item> </a-sub-menu> </a-menu> </a-layout-sider>` <a-list item-layout="vertical" size="large" :grid="{ gutter: 16, column: 3 }" :data-source="ebooks1"> <template #renderItem="{ item }"> <a-list-item key="item.name"> <template #actions> <span v-for="{ type, text } in actions" :key="type"> <component v-bind:is="type" style="margin-right: 8px" /> {{ text }} </span> </template> <a-list-item-meta :description="item.description"> <template #title> <a :href="item.href" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >{{ item.name }}</a> </template> <template #avatar><a-avatar :src="item.cover" /></template> </a-list-item-meta> </a-list-item> </template> </a-list> </a-layout> </template> <script lang="ts"> import { defineComponent,onMounted,ref,reactive,toRef} from 'vue'; import axios from 'axios'; import { StarOutlined, LikeOutlined, MessageOutlined } from '@ant-design/icons-vue'; const listData: Record<string, string>[] = []; export default defineComponent({ components: StarOutlined, LikeOutlined, MessageOutlined, }, name: 'Home', setup(){ const pagination = { onChange: (page: number) => { console.log(page); }, pageSize: 3, }; const actions: Record<string, string>[] = [ { type: 'StarOutlined', text: '156' }, { type: 'LikeOutlined', text: '156' }, { type: 'MessageOutlined', text: '2' }, ]; console.log('set up'); //Use ref for data binding const ebooks=ref(); // Use reactive data binding const ebooks1 = reactive({books:[]}) onMounted(()=>{ axios.get("http://localhost:8888/ebook/list?name=").then(response =>{ console.log("onMounted"); const data=response.data; ebooks.value=data.content; ebooks1.books=data.content; }) }) return { pagination, actions, ebooks1: ebooks, ebooks2:toRef(ebooks1,"books") } } }); </script> <style> .ant-layout-sider{ float: left; } </style> Knowledge points:
Recompile again and see the effect as follows: 2.5. Change the icon style before the list contentEverything looks good, but the book cover is a little small and ugly, as shown below: To change the style, just adjust it in home. The sample code is as follows: html <template> <a-layout> `<a-layout-sider width="200" style="background: #fff"> <a-menu mode="inline" v-model:selectedKeys="selectedKeys2" v-model:openKeys="openKeys" :style="{ height: '100%', borderRight: 0 }" > <a-sub-menu key="sub1"> <template #title> <span> <user-outlined /> subnav 1 </span> </template> <a-menu-item key="1">option1</a-menu-item> <a-menu-item key="2">option2</a-menu-item> <a-menu-item key="3">option3</a-menu-item> <a-menu-item key="4">option4</a-menu-item> </a-sub-menu> <a-sub-menu key="sub2"> <template #title> <span> <laptop-outlined /> subnav 2 </span> </template> <a-menu-item key="5">option5</a-menu-item> <a-menu-item key="6">option6</a-menu-item> <a-menu-item key="7">option7</a-menu-item> <a-menu-item key="8">option8</a-menu-item> </a-sub-menu> <a-sub-menu key="sub3"> <template #title> <span> <notification-outlined /> subnav 3 </span> </template> <a-menu-item key="9">option9</a-menu-item> <a-menu-item key="10">option10</a-menu-item> <a-menu-item key="11">option11</a-menu-item> <a-menu-item key="12">option12</a-menu-item> </a-sub-menu> </a-menu> </a-layout-sider>` <a-list item-layout="vertical" size="large" :grid="{ gutter: 16, column: 3 }" :data-source="ebooks1"> <template #renderItem="{ item }"> <a-list-item key="item.name"> <template #actions> <span v-for="{ type, text } in actions" :key="type"> <component v-bind:is="type" style="margin-right: 8px" /> {{ text }} </span> </template> <a-list-item-meta :description="item.description"> <template #title> <a :href="item.href" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >{{ item.name }}</a> </template> <template #avatar><a-avatar :src="item.cover" /></template> </a-list-item-meta> </a-list-item> </template> </a-list> </a-layout> </template> <script lang="ts"> import { defineComponent,onMounted,ref,reactive,toRef} from 'vue'; import axios from 'axios'; import { StarOutlined, LikeOutlined, MessageOutlined } from '@ant-design/icons-vue'; const listData: Record<string, string>[] = []; export default defineComponent({ components: StarOutlined, LikeOutlined, MessageOutlined, }, name: 'Home', setup(){ const pagination = { onChange: (page: number) => { console.log(page); }, pageSize: 3, }; const actions: Record<string, string>[] = [ { type: 'StarOutlined', text: '156' }, { type: 'LikeOutlined', text: '156' }, { type: 'MessageOutlined', text: '2' }, ]; console.log('set up'); //Use ref for data binding const ebooks=ref(); // Use reactive data binding const ebooks1 = reactive({books:[]}) onMounted(()=>{ axios.get("http://localhost:8888/ebook/list?name=").then(response =>{ console.log("onMounted"); const data=response.data; ebooks.value=data.content; ebooks1.books=data.content; }) }) return { pagination, actions, ebooks1: ebooks, ebooks2:toRef(ebooks1,"books") } } }); </script> <style scoped> .ant-layout-sider{ float: left; } .ant-avatar { width: 50px; height: 50px; line-height: 50px; border-radius: 8%; margin: 5px 0; } </style> Recompile again and check the following: This is the end of this article about the details of Vue3 list interface data display. For more relevant Vue3 list interface data display content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Detailed explanation of the new background properties in CSS3
>>: UCenter Home site adds statistics code
Table of contents 1. What is the life cycle 2. Lo...
First of all, what is 404 and soft 404? 404: Simpl...
Whether MySQL needs to commit when performing ope...
I haven't worked with servers for a while. No...
Socket option function Function: Methods used to ...
Many people now live on the Internet, and searchin...
Table of contents 1. Detailed syntax of entires()...
Preface The Boost library is a portable, source-c...
It is very common to highlight images on a page. ...
Preface This article mainly introduces the releva...
Table of contents 1. Let’s start with the conclus...
Detailed explanation of HTML (select option) in ja...
In MySQL, the LOAD_FILE() function reads a file a...
1. Introduction Image maps allow you to designate...
The full name of Blog should be Web log, which me...