学习记录:微信原生小程序

注册账号

https://developers.weixin.qq.com/miniprogram/dev/framework/quickstart/ 详情查看微信开放文档

新建项目

登录微信公众平台
登录微信公众平台找到开发管理下的开发设置,找到AppID填入下面输入框中
在这里插入图片描述
一般情况下会选择不使用云服务,选择不使用模板,之后确认好文件位置及项目名称选择确定。

文件介绍

在这里插入图片描述

项目新建成功之后会自动生成以上几种文件:

  • pages文件夹是用来存放小程序各个页面文件的.

         index文件夹代表小程序整个index页面
                  index.js用来存放当前页面的js逻辑,内部包含了小程序页面的生命周期
                  index.json用来存放当前页面的配置,会覆盖掉冲突的公共配置
                  index.wxml用来书写页面代码搭建页面结构,参照html文件
                  index.wxss用来书写当前页面样式,参照css文件
    
  • app.js是用来书写整个小程序整体逻辑,放在小程序的各个生命周期中.

  • app.json用来存放小程序公共配置.

  • app.wxss小程序的公共样式表

  • 在utils中定义方法、工具等,主要使用common.js暴露接口

tabBar页面

几乎所有小程序都会需要配置tabBar页面,tabBar页面最少配置两项最多配置五项。

1、全局公共配置,放在app.json中

在这里插入图片描述
**注意:**新建页面需要在app.json中pages属性中直接添加页面路径,保存后会自动生成页面文件,无需手动新建文件夹

2、自定义tabBar,新建tabbar组件

在这里插入图片描述
由于在某些情况下我们需要特定的tabbar按钮样式、动画样式,此时我们就需要自己设计tabBar组件

  1. 要在app.json文件中的tabbar属性中添加配置 “custom”: true,同时tabbar中其他的一些基础配置也是必须保留的,否则会报错
  2. 在pages文件夹的同级新建"custom-tab-bar"组件文件夹,注意名称必须一致,否则无法识别
    在这里插入图片描述
自定义tabBar案例

app.js

App({
  globalData: {
    selectedIndex: 0
  }
})

index.js
注意:自定义中的pagePath路径必须要以"/pages"开头,公共配置是以“pages”开头,二者要区分开

var app = getApp()
Component({
  
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    selected: 0,
    color: "#7A7E83",
    selectedColor: "#3cc51f",
    list: [
    {
      "pagePath": "/pages/index/index",
      "text": "首页",
      "iconPath": "../img/隐患上报.png",
      "selectedIconPath":"../img/隐患未处置.png"
    },
     {
      "pagePath": "/pages/logs/index",
      "text": "日志",
      "iconPath": "../img/隐患上报.png",
      "selectedIconPath":"../img/隐患未处置.png"
    },
     {
      "pagePath": "/pages/home/index",
      "text": "主页",
      "iconPath": "../img/隐患上报.png",
      "selectedIconPath":"../img/隐患未处置.png"
    }
  ]
  },
  attached() {},
  methods: {
    switchTab(e) {
      const data = e.currentTarget.dataset
      app.globalData.selectedIndex = data.index;
      const url = data.path
      wx.switchTab({
        url
      })
    },
  },
  ready(){
    this.setData({
      selected: app.globalData.selectedIndex
    })
  },
})

index.wxml

<view class="tab-bar">
  <view  wx:for="{{list}}" wx:key="index" class="tab-bar-item" data-path="{{item.pagePath}}" wx:for-index="index" data-index="{{index}}" bindtap="switchTabbar">
    <image class=" {{selected == index?'active':''}}"  src="{{selected===index?item.selectedIconPath:item.iconPath}}"></image>
    <view  class="{{ item.tuqi }}" wx:if="{{ selected===index }}" class="cover-view"  style="color: {{selected === index ? selectedColor : color}} ">{{item.text}}</view>
  </view>
</view>

index.wxss

.tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 48px;
  background: white;
  display: flex;
  padding-bottom: env(safe-area-inset-bottom);
  border-top: 1px solid #ccc;
  border-top-left-radius: 25rpx;
  border-top-right-radius: 25rpx;
}
.tab-bar-item {
  flex: 1;
  text-align: center;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
}
.tab-bar-item image {
  transition: all .25s ease;
  width: 27px;
  height: 27px;
}
.tab-bar-item .cover-view {
  font-size: 20rpx;
  margin-top: 5rpx;
 
  animation-name: wipe-in-up; /*动画的名称 */
  animation-duration: 1000ms; /*动画从开始到结束的时间*/
}
.active {
  transition: property duration timing-function delay;
  transform: scale(1.2);
  border-radius: 50rpx;
 
  margin-top: -50rpx;
  transform: translateY(-10rpx); 
 
  animation-name: wipe-in-up; /*动画的名称 */
  animation-duration: 1000ms; /*动画从开始到结束的时间*/
 
}
 
@keyframes wipe-in-up {
  from {
    clip-path: inset(100% 0 0 0);
  }
 
  to {
    clip-path: inset(0 0 0 0);
  }
}
 
[transition-style="in:wipe:up"] {
  animation: 2.5s cubic-bezier(.25, 1, .30, 1) wipe-in-up both;
}
 
.tq {
  margin-top: -50rpx;
}
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值