1.24.3 • Published 6 months ago

mipp-ali v1.24.3

Weekly downloads
12
License
MIT
Repository
github
Last release
6 months ago

Mipp-ali

小程序 typescript 基类

Installation

使用 class 风格时,小程序继承的父类

Import

Import PageBase:

import { PageBase } from "mipp";

or import all:

import Mipp from "mipp-ali";

Api

  • PageBase

Interface

  • IMippWeApp
  • IMippWePage
  • IMippWeComponent
  • IMippWeEvent
  • IMippWeCommon

PageBase

逻辑页面的父类,所有页面都需要继承该父类;

<IData>

是页面渲染的数据类或 interface,即data中所包含的数据或者 interface

特别注意 constructor构造方法中不能使用小程序内置的属性和方法;比如:this.setData(opts?)this.options;因为此时还没有注入到 Page 函数中,并没有小程序内置的对象

(除非必须)尽量不要在 constructor里面执行初始化的工作,因为加载小程序后,会执行所有页面前置的 js 代码(Page()之前执行的代码),导致小程序渲染变慢。可以在onLoad生命周期函数中执行初始化的工作,onLoad只在打开该页面时执行

data初始化

data初始化有两种方式:

  1. constructor中初始化,使用this.data = new Data()data进行初始化;建议使用这方式
  2. onLoad中初始化,在onLoad中初始化需要执行this.setData()
data初始化示例
  • 建议使用在constructor中初始化:
class Data {
  username = "";
}


class Index extends PageBase<Data> implements IMippWePage.ILifetime {
  data: Data;

  constructor () {
    super();
    this.data = new Data();
  }

  onLoad(): void {
    console.log("onLoad", this);
  }
}

Page(new Index());
  • onLoad中初始化:
class Data {
  username = "";
}


class Index extends PageBase<Data> implements IMippWePage.ILifetime {
  data: Data;

  onLoad(): void {
    this.setData(new Data());
    console.log("onLoad", this);
  }
}

Page(new Index());

Example1

class Data {
  username = "";
}


class Index extends PageBase<Data> implements IMippWePage.ILifetime {
  data: Data;

  constructor () {
    super();
    this.data = new Data();
    //不能在constructor中使用 this.setData({}); 因为还没有注入到Page函数中,并没有小程序内置的对象
  }

  onLoad(): void {
    console.log("onLoad", this);
  }
}

Page(new Index());

Example2

class Data {
  username = "";
}

// 不推荐的方式
class Index extends PageBase<Data> implements IMippWePage.ILifetime {
  data = new Data();

  onLoad(): void {
    console.log("onLoad", this);
  }
}

// 推荐的方式
class Index extends PageBase<Data> implements IMippWePage.ILifetime {
  data: Data;

  constructor() {
    super();
    this.data = new Data();
  }

  onLoad(): void {
    console.log("onLoad", this);
  }
}

Page(new Index());

IMippWePage.ILifetime

小程序生命周期函数的 interface

{
  onLoad
  onShow
  onReady
  onHide
  onUnload
  onPullDownRefresh
  onReachBottom
  onShareAppMessage
  onPageScroll
  onTabItemTap
  onResize
  onAddToFavorites
}

Example

interface IData {
  username: string;
}

class Index extends PageBase<IData> implements IMippWePage.ILifetime {
  data: IData = {
    username: "",
  };

  onLoad(): void {
    console.log("onLoad", this);
  }
}

Page(new Index());
1.24.3

6 months ago

1.24.1

8 months ago

1.24.2

8 months ago

1.24.0

8 months ago

1.19.10

10 months ago

1.19.11

10 months ago

1.21.0

9 months ago

1.23.2

8 months ago

1.23.3

8 months ago

1.23.0

8 months ago

1.23.1

8 months ago

1.19.0

10 months ago

1.19.4

10 months ago

1.19.3

10 months ago

1.19.2

10 months ago

1.19.1

10 months ago

1.19.8

10 months ago

1.19.7

10 months ago

1.19.6

10 months ago

1.19.5

10 months ago

1.19.9

10 months ago

1.22.0

9 months ago

1.20.0

9 months ago

1.22.3

9 months ago

1.22.1

9 months ago

1.22.2

9 months ago

1.14.1

2 years ago

1.12.3

2 years ago

1.14.0

2 years ago

1.12.2

2 years ago

1.12.1

2 years ago

1.12.0

2 years ago

1.18.1

2 years ago

1.12.7

2 years ago

1.18.0

2 years ago

1.14.4

2 years ago

1.12.6

2 years ago

1.16.1

2 years ago

1.14.3

2 years ago

1.12.5

2 years ago

1.16.0

2 years ago

1.12.4

2 years ago

1.18.5

2 years ago

1.18.4

2 years ago

1.18.3

2 years ago

1.18.2

2 years ago

1.18.9

2 years ago

1.18.8

2 years ago

1.18.7

2 years ago

1.18.6

2 years ago

1.11.13

2 years ago

1.15.0

2 years ago

1.13.2

2 years ago

1.13.1

2 years ago

1.13.0

2 years ago

1.17.0

2 years ago

1.18.21

2 years ago

1.18.20

2 years ago

1.1.12

2 years ago

1.18.12

2 years ago

1.18.11

2 years ago

1.18.10

2 years ago

1.18.16

2 years ago

1.18.15

2 years ago

1.18.14

2 years ago

1.18.13

2 years ago

1.18.19

2 years ago

1.18.18

2 years ago

1.18.17

2 years ago

1.1.10

3 years ago

1.1.9

3 years ago

1.1.8

3 years ago

1.1.7

3 years ago

1.1.6

3 years ago

1.1.4

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.1.0

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago