当前位置:网站首页>Custom components in applets
Custom components in applets
2022-07-01 04:04:00 【richest_ qi】
List of articles
Applet project
The main files involved in the code are :
- app.json
- pages/index/index.wxml
- pages/index/index.wxss
- pages/index/index.js
app.json
{
"pages": [
"pages/index/index"
],
"window": {
"navigationBarBackgroundColor": "#971a22",
"navigationBarTitleText": " home page ",
"navigationBarTextStyle": "white"
},
"style": "v2",
"sitemapLocation": "sitemap.json"
}
pages/index/index.wxml
<view class="indexContainer">
<view class="recommendSongContainer">
<view class="header">
<view class="title"> Recommended song list </view>
<view>
<text class="desc"> Meet your true love song list </text>
<text class="btn">></text>
</view>
</view>
<scroll-view class="recommendSongList" enable-flex scroll-x>
<view class="recommendItem" wx:for="{
{list}}" wx:key="id">
<image src="{
{item.picUrl}}"></image>
<view class="name">{
{item.title}}</view>
</view>
</scroll-view>
</view>
<view class="newSongContainer">
<view class="header">
<view class="title"> New song express </view>
<view>
<text class="desc"> More fresh music, more quick fall </text>
<text class="btn">></text>
</view>
</view>
</view>
<view class="newDiscContainer">
<view class="header">
<view class="title"> New dishes are on the shelves </view>
<view>
<text class="desc"> The new magic disc sounds so popular </text>
<text class="btn">></text>
</view>
</view>
</view>
<view class="screamSongContainer">
<view class="header">
<view class="title"> Scream new song list </view>
<view>
<text class="desc"> Trendsetters must listen to the hot new list </text>
<text class="btn">></text>
</view>
</view>
</view>
</view>
pages/index/index.wxss
.indexContainer{
padding: 0 20rpx;
}
.header{
display: flex;
justify-content: space-between;
align-items: center;
margin: 20rpx 0;
}
.header .title{
font-weight: bold;
}
.header .desc{
font-size: 24rpx;
color: #333;
padding: 0 20rpx;
}
.header .btn{
font-size: 24rpx;
padding: 0 10rpx;
background: #eee;
color: #888;
border-radius: 6rpx;
}
.recommendSongList{
display: flex;
height: 280rpx;
}
.recommendSongList image{
width: 200rpx;
height: 200rpx;
border-radius: 10rpx;
margin-right: 10rpx;
}
.recommendSongList .name{
font-size: 26rpx;
display: -webkit-box;
overflow: hidden;
text-overflow:ellipsis;
-webkit-box-orient: vertical;
-webkit-line-clamp: 2;
}
pages/index/index.js
Page({
data:{
list:[]
},
onLoad(){
this.getDataFromServer();
},
getDataFromServer(){
const result = [
{
id: 494479726, picUrl: "https://p2.music.126.net/58ox3zVEmosSrdLaKj6x5w==/109951162827155600.jpg", title: " Back shake MV | It turns out that back shaking can also be visualized "},
{
id: 135595185, picUrl: "https://p2.music.126.net/11ZHf0G9FQzWNi-8sFzCmw==/109951164541050373.jpg", title: "Acid Jazz Acid jazz — In Jazz “ Acidic ” The fusion "},
{
id: 114846926, picUrl: "https://p2.music.126.net/GTf1b1G2dAs1SleurIfcJg==/3399689953594431.jpg", title: " The suffixes of song titles are popular science "},
{
id: 113780871, picUrl: "https://p2.music.126.net/qxUWSKhrd1UWME8oAYTMFQ==/109951164497486331.jpg", title: "「Cool Jazz」 Cold Jazz makes you relax "},
{
id: 2962407224, picUrl: "https://p2.music.126.net/NW1GEN3sruiLpT4AZrdDFw==/109951165669533032.jpg", title: "『 British female voice 』 The surviving and independent British rose "},
{
id: 2107922801, picUrl: "https://p2.music.126.net/b--QkIcFfdxz_DryW55ZfA==/109951163165101034.jpg", title: " Acoustooptic aesthetics I Classical soundtrack in classic movies "},
{
id: 78669437, picUrl: "https://p2.music.126.net/AfN_yyi-fQe8POTMKJFjAA==/7957165650297535.jpg", title: " Divine episode in American drama "},
{
id: 3116763088, picUrl: "https://p2.music.126.net/MSom1XSXqt5K9ArZlJ29CQ==/109951164608648583.jpg", title: " The power of music I Secular love songs of the Renaissance "},
{
id: 101354498, picUrl: "https://p2.music.126.net/dmj9iqz8MsD_sCd1xBF0WA==/7918682744429845.jpg", title: " Fashion sports • Essential rhythm "}
]
this.setData({
list:result})
}
})
Custom components
Create a new folder under the project root directory :components
,components I'm gonna go ahead and create a new folder :Header
,Header Under the new Component, Automatic file generation : Header.wxml
、Header.wxss
、Header.js
and Header.json
.
The documents involved in the code change are :
- components/Header/Header.wxml
- components/Header/Header.wxss
- components/Header/Header.js
- pages/index/index.json
- pages/index/index.wxml
- pages/index/index.wxss
components/Header/Header.wxml
<view class="header">
<view class="title">{
{title}}</view>
<view>
<text class="desc">{
{desc}}</text>
<text class="btn">></text>
</view>
</view>
components/Header/Header.wxss
.header{
display: flex;
justify-content: space-between;
align-items: center;
margin: 20rpx 0;
}
.header .title{
font-weight: bold;
}
.header .desc{
font-size: 24rpx;
color: #333;
padding: 0 20rpx;
}
.header .btn{
font-size: 24rpx;
padding: 0 10rpx;
background: #eee;
color: #888;
border-radius: 6rpx;
}
components/Header/Header.js
Component({
properties: {
title:{
type:String,
value:" Default title "
},
desc:{
type:String,
value:" Default description "
}
},
data: {
},
methods: {
}
})
pages/index/index.json
{
"usingComponents": {
"Header":"/components/Header/Header"
}
}
pages/index/index.wxml
<view class="indexContainer">
<view class="recommendSongContainer">
<Header title=" Recommended song list " desc=" Meet your true love song list "/>
<scroll-view class="recommendSongList" enable-flex scroll-x>
<view class="recommendItem" wx:for="{
{list}}" wx:key="id">
<image src="{
{item.picUrl}}"></image>
<view class="name">{
{item.title}}</view>
</view>
</scroll-view>
</view>
<view class="newSongContainer">
<Header title=" New song express " desc=" More fresh music, more quick fall "/>
</view>
<view class="newDiscContainer">
<Header title=" New dishes are on the shelves " desc=" The new magic disc sounds so popular "/>
</view>
<view class="screamSongContainer">
<Header title=" Scream new song list " desc=" Trendsetters must listen to the hot new list "/>
</view>
</view>
pages/index/index.wxss
.indexContainer{
padding: 0 20rpx;
}
.recommendSongList{
display: flex;
height: 280rpx;
}
.recommendSongList image{
width: 200rpx;
height: 200rpx;
border-radius: 10rpx;
margin-right: 10rpx;
}
.recommendSongList .name{
font-size: 26rpx;
display: -webkit-box;
overflow: hidden;
text-overflow:ellipsis;
-webkit-box-orient: vertical;
-webkit-line-clamp: 2;
}
Summary
Create custom components
Use... In wechat applet Component()
Implement custom components , It takes an object as a parameter , The object contains multiple attributes , among , Commonly used :
properties
, External properties of components , amount to vue or react Medium props. The type isObject Map
, Not required . Such as
properties: {
title:{
type:String, // Type of attribute , Required
value:" Default title " // The initial value of the property , Not required
}
}
data
, Data inside the component itself . The type isObject
, Not required .methods
, Component approach .
Use custom components
Before using custom components , First, on the page json
Make a reference statement in the document , As shown below , such , Page wxml
You can use custom components just like basic components .
{
"usingComponents": {
"Header":"/components/Header/Header"
}
}
Related links
Use scroll-view Possible problems and solutions in implementing slider view
Introduction to custom components
Component Constructors
边栏推荐
- 187. repeated DNA sequences
- Grid system in bootstrap
- 京东智能客服言犀意图体系搭建和意图识别技术介绍
- Use selenium automated test tool to climb the enrollment score line and ranking of colleges and universities related to the college entrance examination
- Its appearance makes competitors tremble. Interpretation of Sony vision-s 02 products
- [TA frost wolf \u may- hundred people plan] 2.4 traditional empirical lighting model
- TS type gymnastics: illustrating a complex advanced type
- LetCode 1829. Maximum XOR value per query
- 8. 字符串转换整数 (atoi)
- 283.移动零
猜你喜欢
多次跳槽后,月薪等于老同事的年薪
【TA-霜狼_may-《百人计划》】1.2.3 MVP矩阵运算
【TA-霜狼_may-《百人计划》】1.3纹理的秘密
"Target detection" + "visual understanding" realizes the understanding of the input image
Deep learning | rnn/lstm of naturallanguageprocessing
LeetCode 1828. Count the number of points in a circle
Access denied for user ‘ODBC‘@‘localhost‘ (using password: NO)
【TA-霜狼_may-《百人计划》】2.2 模型与材质空间
Unexpected token o in JSON at position 1, JSON parsing problem
采购数智化爆发在即,支出宝'3+2'体系助力企业打造核心竞争优势
随机推荐
431. 将 N 叉树编码为二叉树 DFS
【TA-霜狼_may-《百人计划》】1.2.1 向量基础
程序员女友给我做了一个疲劳驾驶检测
[ta - Frost Wolf May - 100 people plan] 1.2.1 base vectorielle
Valid @suppresswarnings warning name
Analysis and case of pageobject mode
205. isomorphic string
【TA-霜狼_may-《百人計劃》】2.3 常用函數介紹
MFC window scroll bar usage
嵌入式系統開發筆記80:應用Qt Designer進行主界面設計
MallBook:后疫情时代下,酒店企业如何破局?
[JPCs publication] the Third International Conference on control theory and application in 2022 (icocta 2022)
Do280 management application deployment --rc
Millet College wechat scanning code login process record and bug resolution
165. 比较版本号
Jenkins automatically cleans up construction history
Recommend the best product development process in the Internet industry!
Deep learning | rnn/lstm of naturallanguageprocessing
TS type gymnastics: illustrating a complex advanced type
Note de développement du système embarqué 80: application du concepteur Qt à la conception de l'interface principale