当前位置:网站首页>[wechat applet] to solve button, input and image components
[wechat applet] to solve button, input and image components
2022-07-01 06:32:00 【Front end Xiao Liu is not afraid of cattle】
Hello, audience , This is the front-end blog of Xiao Liu who is not afraid of cattle , Above, we explained the view container component and basic content component of the applet , Small programs also have a common class of components , Form components .
So today, , Let Niuniu take you into the form component (˵◕ω◕˵).

List of articles
One ,button Components
The first one to introduce is button Components , We can find it and HTML The button label in has the same name , Yes , The component is in WXML It also acts as a button setting function , however , by comparison ,button Components have more functions than the latter , Now let's go into more detail , What does wechat applet provide us button function .
typeattribute , Used to set the style type of the button , There are currently three values ,primarygreen ,defaultwhite ,warnRed , We can understand what they mean from the meaning of their values , Green is important , Red is a warning , These two colors will give users the effect of prompts , The default style is white
The effect is as follows :
tip: Some friends may see some differences in the styles , This may be because you haven't set the latest style version , At this time we need to app.json File settings
"style": "v2"
So the declaration is displayed in the latest style
sizeattribute , Used to set the size of the button , The default isdefault, That's normal size , We can also choose Mini buttons , takesizeSet tomini
The effect is as follows :
plainattribute , Is it hollow out , Transparent background color , The default value isdefault, But let's change it totruewhen
The effect is as follows :
loadingattribute , Whether to set the name with loading Icon , It is usually set after the user clicks or when the page is still loaded , use JS YesloadingData binding and operation with the attribute value of .
The effect is as follows :
form-typeattribute , No default , This property is used forformIn the component , Click on the triggerformComponent'ssubmit\resetevent , When we set the attribute value tosubmitTrigger submit form event , andresetIs the reset form event .
button There are also many powerful properties in the component , such as open-type You can directly call the open capability of wechat , For example, trigger user forwarding, etc , If you are interested, you can learn about
Two ,input Components
The second thing I want to talk about is input Components , The content is expressed as an input box , This component is roughly the same as HTML Medium input The label is the same , Is a native component , However, we should pay attention to the usage of this component
valueattribute , We are familiar with this property , I'm not going to elaborate here , Is to set the initial content of the input box , Generally used as a default value for users , Users may be able to use , Such as gender , The default is male , It should be noted that , This attribute is required in the applettypeattribute , Enter the type of keyboard , When we use applet forms to submit things , You will find that the keyboard it pops up is different , Such as normal text input keyboard , There is also a special password input keyboard , These are implemented by this attribute . The attribute values and descriptions are shown in the following table
| Property value | explain |
|---|---|
| text | Text input keyboard |
| number | Numeric input keyboard |
| idcard | ID card input keyboard |
| safe-password | Password security input keyboard |
passwordattribute , Password type or not , When we set theta to zero true, The entered password will be automatically displayed with a small black dot
The effect is as follows :
placeholderattribute , As a placeholder when the input box is empty , The text inside is usually used to prompt the user
3、 ... and ,image Components
Similar in function to HTML Medium img label , Used to carry pictures , But in use ,image There are several more attributes provided by wechat , More diverse in function , Support JPG、PNG、SVG、WEBP、GIF Equiform , Next, let's talk about the attribute functions of this component .
First of all, I need to say image Components have a default size , Wide for 300px, High for 240px, This means that even if you don't have a picture in it , Empty picture , Without changing its width and height , An empty picture will occupy a width 300px high 240px Space. , As shown below .
<!-- html -->
<image></image>
<!-- css -->
image{
border: solid lightcoral 2px;
}

srcattribute , That goes without saying , AndimgThe label is the same , Refers to the image resource address .modeattribute , This is an important attribute , It sets the cropping of the picture 、 Zoom mode , The default value isscaleToFill, Called zoom mode , That is, do not maintain aspect ratio scaling , Stretch the width and height of the original image to completely fillimageElements , This attribute value is prone to image deformation , Other attribute values are as follows .
| Property value | explain | chart |
|---|---|---|
| aspectFit | Keep the aspect ratio scaled , It's a picture The long side can be completely displayed , Can display the picture completely , But the short side image Components may have blank blocks | ![]() |
| aspectFill | Keep the aspect ratio scaled , Only the short side can be fully displayed , in other words , The long side may be intercepted because it is too long | ![]() |
| widthFix | image The width of the element does not change , Automatic height change , The width and height of the original drawing remain unchanged | - |
| heightFit | image The height of the element does not change , The width changes automatically , The width and height of the original drawing remain unchanged | - |
| center | Cut pattern , Unscaled picture , Show only the middle part of the picture | ![]() |
show-menu-by-longpressattribute , Long press the picture to display the menu , Send it to a friend \ Collection \ Save the picture \ Search for … The default value isfalse, This may be common in use , It is often set on QR code pictures
Four ,API Three broad categories
Finally, let's talk about API Three categories of ,API It can be divided into event monitoring API、 Sync API、 asynchronous API
4.1 Event monitoring API
seeing the name of a thing one thinks of its function , This kind API It is used to monitor the triggering of certain events , Events are the communication mode from the rendering layer to the logic layer , We get the user's behavior in the rendering layer through event listening , So as to respond at the logical layer 、 Business processing .
- This kind of API With
onstart , Such aswx.onWindowResize(function callback), Listen for window size changes , If the trigger , That is, call the following callback function . wxObject in the applet is equivalent to the browserwindow, It belongs to the top-level object of wechat applet , Can be called globally
4.2 Sync API
- With
Syncending , The result of execution can be obtained directly through the return value of the function , But when the execution is wrong , Return the exception directly - Such as
wx.setStorageSync('key', 'value'), Write content to local storage
4.3 asynchronous API
- adopt success、false、conplete Receive the result of the call
- Such as
wx.request(), Initiate network request , Can passsuccessThe callback function receives data
First of all, this time API Make a simple description of the classification of , We will use these examples later API
That's the end of this article , If it helps you , You can pay attention to Niuniu's subsequent articles , Thank you for your support !
Debt see ~~
边栏推荐
- C语言课设职工信息管理系统(大作业)
- [ITSM] what is ITSM and why does it department need ITSM
- Pol8901 LVDS to Mipi DSI supports rotating image processing chip
- 常用快捷键
- mysql数据类型学习笔记
- TCL statements in SQL (transaction control statements)
- libpng12.so. 0: cannot open shared object file: no such file or directory
- DML statement in SQL (data operation language)
- Design of sales management system for C language course (big homework)
- [unity shader stroke effect _ case sharing first]
猜你喜欢

C语言课设学生考勤系统(大作业)

数据库产生死锁了请问一下有没有解决办法

C语言课设物业费管理系统(大作业)

High order binary balanced tree

Application of IT service management (ITSM) in Higher Education
![[self use of advanced mathematics in postgraduate entrance examination] advanced mathematics Chapter 1 thinking map in basic stage](/img/54/f187e22ad69f3985d30376bad1fa03.png)
[self use of advanced mathematics in postgraduate entrance examination] advanced mathematics Chapter 1 thinking map in basic stage

图片服务器项目测试

【KV260】利用XADC生成芯片温度曲线图

关于变量是否线程安全的问题

Promise
随机推荐
sql中TCL语句(事务控制语句)
HCM Beginner (II) - information type
存储函数学习笔记
三说 拷贝构造之禁用
做技术,自信不可或缺
mysql学习
子类调用父类的同名方法和属性
C language course set up property fee management system (big work)
Student attendance system for C language course (big homework)
[ManageEngine] how to realize network automatic operation and maintenance
High order binary balanced tree
To sort out the anomaly detection methods, just read this article!
SQL statement
C语言课设学生选修课程系统(大作业)
DML statement in SQL (data operation language)
@Propagation property of transactional requires_ New in-depth understanding
sci-hub如何使用
Comment imprimer le tableau original
Self confidence is indispensable for technology
json模块


