首先我们要明确小程序需要哪几种文件。
微信小程序中就四种类型的文件:
js ---------- JavaScrip文件
json -------- 项目配置文件,负责窗口颜色等等
wxml ------ 类似HTML文件
wxss ------- 类似CSS文件
在根目录下用app来命名的这四种类型的文件,就是程序入口文件。具体介绍如下:
app.json
必须要有这个文件,如果没有这个文件,IDE会报错,因为微信框架把这个作为配置文件入口,
你只需创建这个文件,里面写个大括号就行。以后我们会在这里对整个小程序的全局配置。记录了页面组成,配置小程序的窗口 背景色,配置导航条样式,配置默认标题。
app.js
必须要有这个文件,没有也是会报错!但是这个文件创建一下就行 什么都不需要写
以后我们可以在这个文件中监听并处理小程序的生命周期函数、声明全局变量。
app.wxss
这个文件不是必须的。因为它只是个全局CSS样式文件
app.wxml
这个也不是必须的,而且这个并不是指主界面哦~因为小程序的主页面是靠在JSON文件中配置来决定的
有了这两个文件你运行程序,IDE就不会报错了。
接下来我会向大家介绍一下商城小程序小程序
首先先向大家展示一下效果。
1.app.js
import {log, promiseHandle} from 'utils/util';
App({
getUserInfo(cb) {
if (typeof cb !== "function") return;
let that = this;
if (that.globalData.userInfo) {
cb(that.globalData.userInfo);
} else {
promiseHandle(wx.login).then(() => promiseHandle(wx.getUserInfo)).then(res => {
that.globalData.userInfo = res.userInfo;
cb(that.globalData.userInfo);
}).catch(err => {
log(err);
});
}
},
globalData: {
userInfo: null
},
//自定义配置
settings: {
debug: true, //是否调试模式
moreLink: 'http://github.com/oopsguy'
}
});
2.app.json
{
"pages":[
"pages/index/index",
"pages/detail/detail"
],
"window":{
"backgroundTextStyle":"light",
"navigationBarBackgroundColor": "#E14848",
"navigationBarTitleText": "事项助手",
"navigationBarTextStyle":"white"
}
}
3.aap.wxss
page {
font-family: 'microsoft yahei ui';
font-size: 28rpx;
background-color: #1D1D26;
color: #FFF;
}
/*float action*/
.float-container {
position: fixed;
bottom: 40rpx;
right: 40rpx;
overflow: hidden;
}
.float-action {
width: 100rpx;
height: 100rpx;
border-radius: 50%;
box-shadow: 2px 2px 10px rgba(0, 0, 0, .5);
background: #E14848;
z-index: 100;
text-align: center;
opacity: .5;
margin-left: 40rpx;
float: right;
}
.float-action:active {
opacity: 1
}
.float-action image {
width: 60rpx;
height: 60rpx;
margin-top: 20rpx;
}
后期会持续更新小程序源码,有的会在公众号发布。(友友集结地)