Home >Web Front-end >uni-app >How to use container component development in uniapp
How to use container component development in uniapp
Overview:
In uniapp, the container component is a common component in the page, used to wrap other components or content, and serve as layout and control elements. Display function. In this article, we will introduce how to use container component development in uniapp and provide relevant code examples.
1. Common container components in uniapp
2. Development example using view container component
d477f9ce7bf77f53fbcf36bec1b69b7a
< ;view class="container">
<text class="text">Hello, Uniapp!</text>
de5f4c1163741e920c998275338d29b2
21c97d3a051048b8e55e3c8f199a54b2
c9ccee2e6ea535a969eb3f532ad9fe89
.container {
width: 100%;
height: 200rpx;
background-color: #f5f5f5;
margin-top: 10rpx;
padding : 10rpx;
}
.text {
font-size: 32rpx;
color: #333333;
}
531ac245ce3e4fe3d50054a55f265927
The above code implements a view container with a height of 200rpx and a background color of #f5f5f5, and a text element is nested in it. By setting the margin and padding properties, the separation between the container and external elements and the separation between internal elements are achieved.
3. Development example using scroll-view container component
d477f9ce7bf77f53fbcf36bec1b69b7a
32ce4af5baa878d1e388c81f01e55bcb
<text class="text">Lorem ipsum dolor sit amet, consectetur adipiscing elit. In consequat vel velit vitae aliquet.</text>
ffff89ca6bf3cfa196013784bbead6a0
21c97d3a051048b8e55e3c8f199a54b2
c9ccee2e6ea535a969eb3f532ad9fe89
.container {
width: 100%;
height: 300rpx;
background-color: #f5f5f5;
margin -top: 10rpx;
padding: 10rpx;
}
.text {
font-size: 32rpx;
color: #333333;
white-space: pre-wrap;
}
531ac245ce3e4fe3d50054a55f265927
The above code implements a scroll-view container that can be scrolled vertically, and the content is a piece of text. By setting the height and overflow properties of scroll-view, the scrollable effect is achieved when the content exceeds the height of the container.
4. Development examples using swiper and swiper-item container components
d477f9ce7bf77f53fbcf36bec1b69b7a
bc9cbe5bf5d3e4649a72782e7cd12ead
<swiper-item> <image src="path/to/image1"></image> </swiper-item> <swiper-item> <image src="path/to/image2"></image> </swiper-item> <swiper-item> <image src="path/to/image3"></image> </swiper-item>
00d60d359d79ef3ad471162a03ef38f0
21c97d3a051048b8e55e3c8f199a54b2
c9ccee2e6ea535a969eb3f532ad9fe89
.container {
width: 100%;
height: 300rpx;
margin-top: 10rpx;
}
531ac245ce3e4fe3d50054a55f265927
The above code implements a picture carousel effect, which is achieved by setting the height of the swiper and swiper-item components. A sliding display of pictures.
Summary:
Container components play an important role in layout and control element display in uniapp development. This article introduces common container components in uniapp and provides corresponding code examples. I hope it will be helpful to everyone in developing using container components. By learning and mastering the use of container components, you can better develop uniapp pages.
The above is the detailed content of How to use container component development in uniapp. For more information, please follow other related articles on the PHP Chinese website!