当前位置:网站首页>微信小程序开发入门介绍-布局组件
微信小程序开发入门介绍-布局组件
2022-06-21 15:53:00 【低代码布道师】
在小程序开发中比较重要的就是布局了。所谓的布局是依据美工提供的设计稿,按照工具提供的各类组件进行实现。小程序中我们常用的布局组件是view。通过布局组件就可以实现我们想要的效果。
布局组件的添加
我们还是使用可视化的方式进行搭建,在控制台点击可视化,点击view组件,给页面中增加一个组件。
小程序的布局组件是view,微搭中的布局组件叫普通容器,同样的我们也可以往页面中添加一个普通容器组件
所谓的布局,其实就类似于我们使用word进行排版,比如我们可以插入表格,表格是分为行和列,那几行和几列就可以实现我们一般的页面的布局效果。比如我们要实现一个一行两列的效果,我们先看低代码中如何实现。
低码中实现一行两列布局
低码中如果要实现一行两列的效果,先需要容器进行嵌套
如果我们不设置样式,默认组件是从上到下排列的,如果想改成从左到右排列,那就需要在外层普通容器设置样式,一般弹性布局可以做到。我们设置外层普通容器的样式为弹性布局,主轴方向为水平,主轴和副轴对齐都是居中。
普通容器默认是填满屏幕的,为了实现两列,我们还需要给内层的普通容器的宽度都设置为50%,这样就是实现了一行两列的布局
微信开发者工具实现一行两列布局
在低码中是可视化的方式设置样式的,那在微信开发者工具如何做到呢?同理我们也是要实现嵌套
<view style="position:relative; width: 100%; background: #d3d3d3; height: 100px">
<view style="position:relative; width: 100%; background: #df1b1b; height: 100px"></view>
<view style="position:relative; width: 100%; background: #401ed8; height: 100px"></view>
</view>
其实代码的模式和低码的模式原理是相通的,同样的我们需要在外层的view设置样式,样式的话我们可以粘贴低码编辑器里生成的
微信开发者工具的样式可以写在index.wxss文件里
.outer{
display: flex;
justify-content: center;
align-items: center;
flex-direction: row
}
然后可以在外层的view里添加一个样式类,调用index.wxss文件里的样式
<view class="outer" style="position:relative; width: 100%; background: #d3d3d3; height: 100px">
<view style="position:relative; width: 100%; background: #df1b1b; height: 100px"></view>
<view style="position:relative; width: 100%; background: #401ed8; height: 100px"></view>
</view>

总结
我们本篇对比了一下低码和微信开发者工具中如何实现页面的布局,双方实现方式是一致的,都是添加组件、定义样式。区别是低码是纯可视化话配置,微信开发者工具得手写代码。从开发效率看,纯配置的模式记忆的知识点更少,开发效率更高。后续我们会继续对比两种工具之间的不同,敬请期待。
边栏推荐
- Advanced performance test series 5. server development, VMware virtual technology
- 海瑞科技完成数千万元Pre-A轮融资,打造国内首个人工智能配电物联网
- Typescript (6) function
- Advanced performance test series 6. problem solving and application development
- Research Report on the overall scale, major producers, major regions, products and applications of autothermal reforming units in the global market in 2022
- 如何编写测试用例
- Standing at the digital tuyere, how can tooling enterprises "fly"
- Advanced performance test series 2. software performance test, load test and stress test
- Score-Based Generative Modeling through Stochastic Differential Equations
- 20000 words + 30 pictures | what's the use of chatting about MySQL undo log, redo log and binlog?
猜你喜欢

Huawei cloud releases desktop ide codearts

IDC咨询:2022年中国关系型数据库软件市场,变革即将到来

Gold, silver and four are coming soon. What do you need to prepare for looking for a job?

学习软件“学习通”数据库疑似发生信息泄露,泄露学生信息达1亿多条

Implementation and landing of any to any real-time voice change RTC dev Meetup

站在数字化风口,工装企业如何'飞起来'

About SQL: does anyone in SQL know how to answer these questions?

Baota, a well-known server operation and maintenance software manufacturer, joined dragon lizard community and completed compatibility and adaptation with Anolis OS

Huawei cloud releases desktop ide codearts

20000 words + 30 pictures | what's the use of chatting about MySQL undo log, redo log and binlog?
随机推荐
Simulation Implementation of string class
What has paileyun done to embrace localization and promote industrial Internet?
2021数据库市场,Aerospike与顶级厂商争锋
Introduction to mqtt protocol
学习软件“学习通”数据库疑似发生信息泄露,泄露学生信息达1亿多条
堪称神作!啃透这份JVM笔记,轻松搞定阿里30K面试!
IDC咨询:2022年中国关系型数据库软件市场,变革即将到来
Go language development code self test excellent go fuzzing usage explanation
华为云发布桌面IDE-CodeArts
Cisco(35)——BGP入门实验
我敢闯 我会创!第八届“互联网 +”大赛GaussDB命题开放报名啦!
Any to Any 实时变声的实现与落地丨RTC Dev Meetup
Goose factory, everything about ThreadLocal
海瑞科技完成数千万元Pre-A轮融资,打造国内首个人工智能配电物联网
NFT卡牌链游系统开发详情分析
SQLSTATE[42000]: Syntax error or access violation: 1055 Expression #1 of SELECT list is not in GROUP
2022年Q1手机银行用户规模达6.5亿,加强ESG个人金融产品创新
一个好产品应该具备的特征
Web网页自动化实战《5.获取所有酒店的名字、价格、评分信息,并写入文件》下篇
Huawei cloud released the white paper on cloud native 2.0 architecture, and the gaussdb technology was upgraded again