当前位置: 首页 > news >正文

微信小程序------代码构成

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

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 的角色。

<view class="container">
  <view class="userinfo">
    <button wx:if="{{!hasUserInfo && canIUse}}"> 获取头像昵称 </button>
    <block wx:else>
      <image src="{{userInfo.avatarUrl}}" background-size="cover"></image>
      <text class="userinfo-nickname">{{userInfo.nickName}}</text>
    </block>
  </view>
  <view class="usermotto">
    <text class="user-motto">{{motto}}</text>
  </view>
</view>

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

相关文章:

  • 斐波那契数列集锦
  • java学习书籍推荐
  • HDU 1568 Fibonacci
  • Hadoop2.6.0单机伪分布式安装
  • jquery获取表单值的利器:serialize()
  • COGS.264.数列操作(分块 单点加 区间求和)
  • HDU 2196 Computer 经典树形DP
  • 【python】-字典的使用
  • Android Development Tools for Eclipse.pdf
  • 推荐引擎算法学习导论
  • 使用 RAID 与 LVM 磁盘阵列技术
  • C#脚本实践(六): 脚本相对于C++的优势
  • 二维数组作为函数参数传递剖析(转载)
  • 基于贝叶斯平均的产品排序方法
  • Oracle Database Instant Client即时客户端配置使用
  • 收藏网友的 源程序下载网
  • 5分钟即可掌握的前端高效利器:JavaScript 策略模式
  • Babel配置的不完全指南
  • Gradle 5.0 正式版发布
  • HomeBrew常规使用教程
  • IIS 10 PHP CGI 设置 PHP_INI_SCAN_DIR
  • Java 内存分配及垃圾回收机制初探
  • JAVA并发编程--1.基础概念
  • k8s如何管理Pod
  • Perseus-BERT——业内性能极致优化的BERT训练方案
  • Python socket服务器端、客户端传送信息
  • Vim Clutch | 面向脚踏板编程……
  • 阿里云前端周刊 - 第 26 期
  • 读懂package.json -- 依赖管理
  • 前端技术周刊 2019-02-11 Serverless
  • 巧用 TypeScript (一)
  • 一道闭包题引发的思考
  • ​DB-Engines 11月数据库排名:PostgreSQL坐稳同期涨幅榜冠军宝座
  • ​LeetCode解法汇总1410. HTML 实体解析器
  • # 达梦数据库知识点
  • #if和#ifdef区别
  • $.extend({},旧的,新的);合并对象,后面的覆盖前面的
  • %@ page import=%的用法
  • (14)学习笔记:动手深度学习(Pytorch神经网络基础)
  • (52)只出现一次的数字III
  • (done) 两个矩阵 “相似” 是什么意思?
  • (html转换)StringEscapeUtils类的转义与反转义方法
  • (读书笔记)Javascript高级程序设计---ECMAScript基础
  • (十八)SpringBoot之发送QQ邮件
  • (一)Mocha源码阅读: 项目结构及命令行启动
  • (转载)PyTorch代码规范最佳实践和样式指南
  • .bat批处理(八):各种形式的变量%0、%i、%%i、var、%var%、!var!的含义和区别
  • .NET Core WebAPI中使用swagger版本控制,添加注释
  • .Net Core/.Net6/.Net8 ,启动配置/Program.cs 配置
  • .NET 发展历程
  • .net经典笔试题
  • .net中的Queue和Stack
  • .Net中的集合
  • .Net转Java自学之路—SpringMVC框架篇六(异常处理)
  • @column注解_MyBatis注解开发 -MyBatis(15)