目录
🍓小程序代码的构成 - WXML 模板
1. 什么是 WXML
WXML(WeiXin Markup Language)是小程序框架设计的一套
标签语言
,
用来构建小程序页面的结构
,其作用类似于网页开发中的 HTML。
2. WXML 和 HTML 的区别
① 标签名称不同HTML (div, span, img, a)WXML(view, text, image, navigator)② 属性节点不同<a href ="#">超链接</a><navigator url ="/pages/home/home"></navigator>③ 提供了类似于 Vue 中的模板语法数据绑定列表渲染条件渲染
<view>aaa</view>
<view>aaa</view>
<div>aaa</div>
<div>aaa</div>
div标签在小程序中不能换行了
🍇小程序代码的构成 - WXSS 样式
1. 什么是 WXSS
WXSS (WeiXin Style Sheets)是一套
样式语言
,用于描述 WXML 的组件样式,类似于网页开发中的 CSS。
2. WXSS 和 CSS 的区别
① 新增了 rpx 尺寸单位CSS 中需要手动进行像素单位换算,例如 remWXSS 在底层支持新的尺寸单位 rpx,在不同大小的屏幕上小程序会自动进行换算② 提供了全局的样式和局部样式项目根目录中的 app.wxss 会作用于所有小程序页面局部页面的 .wxss 样式仅对当前页面生效③ WXSS 仅支持部分 CSS 选择器.class 和 #idelement并集选择器、后代选择器::after 和 ::before 等伪类选择器
当然你可以把HTML和CSS放入小程序中:
效果:

HTML(放入WXML中):
<!--pages/tsj/tsj.wxml-->
<button class="c-button c-button--gooey"> Hover me
<div class="c-button__blobs">
<div></div>
<div></div>
<div></div>
</div>
</button>
<svg style="display: block; height: 0; width: 0;" version="1.1" xmlns="http://www.w3.org/2000/svg">
<defs>
<filter id="goo">
<feGaussianBlur result="blur" stdDeviation="10" in="SourceGraphic"></feGaussianBlur>
<feColorMatrix result="goo" values="1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 18 -7" mode="matrix" in="blur"></feColorMatrix>
<feBlend in2="goo" in="SourceGraphic"></feBlend>
</filter>
</defs>
</svg>
CSS(放入WXSS中):
/* pages/tsj/tsj.wxss */
/* From www.lingdaima.com */
.c-button {
color: #000;
font-weight: 700;
font-size: 16px;
text-decoration: none;
padding: 0.9em 1.6em;
cursor: pointer;
display: inline-block;
vertical-align: middle;
position: relative;
z-index: 1;
}
.c-button--gooey {
color: #06c8d9;
text-transform: uppercase;
letter-spacing: 2px;
border: 4px solid #06c8d9;
border-radius: 0;
position: relative;
transition: all 700ms ease;
}
.c-button--gooey .c-button__blobs {
height: 100%;
filter: url(#goo);
overflow: hidden;
position: absolute;
top: 0;
left: 0;
bottom: -3px;
right: -1px;
z-index: -1;
}
.c-button--gooey .c-button__blobs div {
background-color: #06c8d9;
width: 34%;
height: 100%;
border-radius: 100%;
position: absolute;
transform: scale(1.4) translateY(125%) translateZ(0);
transition: all 700ms ease;
}
.c-button--gooey .c-button__blobs div:nth-child(1) {
left: -5%;
}
.c-button--gooey .c-button__blobs div:nth-child(2) {
left: 30%;
transition-delay: 60ms;
}
.c-button--gooey .c-button__blobs div:nth-child(3) {
left: 66%;
transition-delay: 25ms;
}
.c-button--gooey:hover {
color: #fff;
}
.c-button--gooey:hover .c-button__blobs div {
transform: scale(1.4) translateY(0) translateZ(0);
}
🍒小程序代码的构成 - JS 逻辑交互
1. 小程序中的 .js 文件
一个项目仅仅提供界面展示是不够的,在小程序中,我们通过 .js 文件来处理用户的操作。例如:响应用户的点击、获取用户的位置等等。
2. 小程序中 .js 文件的分类
小程序中的 JS 文件分为三大类,分别是:① app.js是 整个小程序项目的入口文件 ,通过调用 App() 函数 来启动整个小程序② 页面的 .js 文件是 页面的入口文件 ,通过调用 Page() 函数 来创建并运行页面③ 普通的 .js 文件是 普通的功能模块文件 ,用来封装 公共的函数或属性 供页面使用