博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
微信小程序------代码构成
阅读量:4681 次
发布时间:2019-06-09

本文共 3553 字,大约阅读时间需要 11 分钟。

一、创建一个小程序生产如下目录

1.app.json

app.json 是对当前小程序的全局配置,包括了小程序的所有页面路径、界面表现、网络超时时间、底部 tab 等。项目里边的 app.json 配置内容如下:

{  "pages":[    "pages/index/index",    "pages/warn/index",    "pages/scanresult/index",    "pages/billing/index",    "pages/my/index",    "pages/wallet/index",    "pages/charge/index",    "pages/logs/logs"  ],  "window":{    "backgroundTextStyle":"light",    "navigationBarBackgroundColor": "#b9dd08",    "navigationBarTitleText": "单车",    "navigationBarTextStyle":"black"  }}

 

2.WXSS 具有 CSS 大部分的特性,小程序在 WXSS 也做了一些扩充和修改.

/**app.wxss**/.container{    background-color: #f2f2f2;    height: 100vh;}.title{    background-color: #f2f2f2;    padding: 30rpx 0 30rpx 50rpx;    font-size: 28rpx;    color: #000;}.tapbar{    display: flex;    align-items: center;    justify-content: space-between;    background-color: #fff;    padding: 40rpx;}.btn-charge{    width: 90%;    background-color: #b9dd08;    margin: 40rpx auto 30rpx;    text-align: center;}

3.wxml文件, WXML 充当的就是类似 HTML 的角色。

{
{userInfo.nickName}}
{
{motto}}

4.js文件为逻辑交互文件。根据小程序的api编写,这里为部分代码

/ 页面加载  onLoad: function (options) {    // 1.获取定时器,用于判断是否已经在计费    this.timer = options.timer;    // 2.获取并设置当前位置经纬度    wx.getLocation({      type: "gcj02",      success: (res) => {        this.setData({          longitude: res.longitude,          latitude: res.latitude        })      }    });    // 3.设置地图控件的位置及大小,通过设备宽高定位    wx.getSystemInfo({      success: (res) => {        this.setData({          controls: [{            id: 1,            iconPath: '/images/location.png',            position: {              left: 20,              top: res.windowHeight - 80,              width: 50,              height: 50            },            clickable: true          },          {            id: 2,            iconPath: '/images/use.png',            position: {              left: res.windowWidth/2 - 45,              top: res.windowHeight - 100,              width: 90,              height: 90            },            clickable: true          },          {            id: 3,            iconPath: '/images/warn.png',            position: {              left: res.windowWidth - 70,              top: res.windowHeight - 80,              width: 50,              height: 50            },            clickable: true          },          {            id: 4,            iconPath: '/images/marker.png',            position: {              left: res.windowWidth/2 - 11,              top: res.windowHeight/2 - 45,              width: 22,              height: 45            },            clickable: true          },          {            id: 5,            iconPath: '/images/avatar.png',            position: {              left: res.windowWidth - 68,              top: res.windowHeight - 155,              width: 45,              height: 45            },            clickable: true          }]        })      }    });    // 4.请求服务器,显示附近的单车,用marker标记    wx.request({      url: 'https://www.easy-mock.com/mock/59098d007a878d73716e966f/ofodata/biyclePosition',      data: {},      method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT      // header: {}, // 设置请求的 header      success: (res) => {          this.setData({            markers: res.data.data          })      },      fail: function(res) {        // fail      },      complete: function(res) {        // complete      }    })  },

 

转载于:https://www.cnblogs.com/tine/p/8426126.html

你可能感兴趣的文章
unity 中 Tilemap的使用 笔记
查看>>
sort()的多种用法
查看>>
UNIX C 文件权限 Part2_day01
查看>>
linux部署Oracle数据库--创建数据库
查看>>
[LeetCode] 148. Sort List 链表排序
查看>>
Java判断密码强度工具类
查看>>
阶段4-独挡一面\项目-基于视频压缩的实时监控系统\Sprint1-基于Epoll架构的采集端程序框架设计\第1课-Epoll机制精通...
查看>>
jmeter(四十四)常用性能指标分析
查看>>
6个出色的基于JQuery的Tab选项卡实例2010/01/29 16:261. jQuery 选项卡界面 / 选项卡结构菜单教程...
查看>>
F - 八苦を滅した尼公 POJ - 2763 线段树LCA
查看>>
通过jQuery源码学习javascript(一)
查看>>
源码阅读经验谈-slim,darknet,labelimg,caffe(1)
查看>>
SecureCRT配色方案
查看>>
Unity3D 关于yield在collider中的使用
查看>>
spring-mvc xml文件的最基本配置
查看>>
word 新建一行文字不能左对齐
查看>>
jquery选择器
查看>>
IT公司的等级观念
查看>>
百度编辑器ueditor1.4.3配置记录
查看>>
ubuntu12.04开启Framebuffer
查看>>