BeeWepy是基于wepy的一套小程序模板,有一些便捷的设置。
- 代码风格规范请使用 JavaScript Standard Style
- Less mixins请使用 lesshat
- 命名规范使用驼峰命名方式,且命名尽量能够顾名思义,如:变量名
userInfo,方法名getUserInfo,类名、组件名User - 在less中直接使用px,编辑后自动转为rpx
- Clone BeeWepy 仓库到本地;
- 安装依赖
$ npm install; - 在 BeeWepy 根目录下执行
$ wepy dev,生成 dist/ 目录; - 微信开发者工具 —— 新建一个小程序,目录指向生成的 dist/;
- $link: 注册为wepy.page的页面跳转方式
this.$link('/page/home/index')- $back: 返回上一页,非跳转
this.$back()- $toast:吐司提示
this.$toast('吐司提示')- $loading:正在加载提示
this.$loading() // 显示
this.$loading(false) //隐藏- $modal: 模态框
await this.$modal('确定?', '子标题', true)- $db: 同步方式获取以及设置localstorage
this.$db.get('name')
this.$db.set('name', '子标题')- $d/$debug: debug消息
this.$d('消息')
this.$debug('消息')- 在
config/index.js中定义是否需要全局mock数据(isMock), 也可以在特定的请求中覆盖, 生产环境自动覆盖。 isMock决定是否使用mock数据,当isMock=true时根据src/mock/mockConfig.js的设置获取mock数据,当isMock=false时会发送网络请求,并且在请求中删除isMock参数。
let requestData = {
isMock: false,
mobile: '110'
}
await this.POST('/login', requestData)- 不明确定义
usertoken,请求中会默认带上localstorage中的usertoken,一般不需要自带usertoken
let requestData = {
usertoken: this.$parent.globalData.token
mobile: '110'
}
await this.POST('/login', requestData)- 请求url以http或才https开头,不会拼接
domain, mockConfig中定义key时使用全url
await this.POST('/login', requestData) //url为 domain + /login
await this.POST('http://www.baidu.com/login', requestData) //url为 http://www.baidu.com/login- 参数
showToast默认为false时, 调用wepy.showNavigationBarLoading(), 为true时, 调用wepy.showLoading()
- 使用wepy-cli 生成项目,运行后报:
Error: module "npm/lodash/_nodeUtil.js" is not defined
解决方法:
npm i util --no-save && wepy build --no-cache
Tencent/wepy#1294 不保存依赖,安装util,同时 不使用缓存构建
- 微信开发者工具打开dist运行时报TypeError: Cannot read property 'Promise' of undefined
解决方法:
微信开发者工具-->项目-->关闭ES6转ES5。重要:漏掉此项会运行报错。 微信开发者工具-->项目-->关闭上传代码时样式自动补全 重要:某些情况下漏掉此项会也会运行报错。 微信开发者工具-->项目-->关闭代码压缩上传 重要:开启后,会导致真机
computed,props.sync等等属性失效。(参考开发者工具编译报错)
基于 MIT License,请自由的享受、参与开源。
- Fork it
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Added some feature') - Push to the branch (
git push origin my-new-feature) - Create new Pull Request