0.0.3 • Published 4 years ago

tg-css-lib v0.0.3

Weekly downloads
-
License
ISC
Repository
-
Last release
4 years ago

天狗小程序 CSS 样式库使用方法

1.创建 package.json 文件:

npm init

2.通过 npm 进行下载,命令如下:

npm install --save tg-css-lib

执行完命令后会在小程序根目录下生成 node_modules 目录。

3.使用 npm 模块:

小程序开发工具->详情->本地设置->使用npm模块

4.构建 npm :

菜单->工具->构建npm

执行完命令后会在小程序根目录下生成 miniprogram_npm 目录,目录中的内容如下:

5.在 app.wxss 中引入 CSS 样式库:

@import "/miniprogram_npm/tg-css-lib/tg.wxss"

这样引入库后,就可以在 wxml 中使用样式库中的样式了。

6.在 app.js 中引入库文件:

require("tg-css-lib/mixins/mixins");

7.定义主题更换监听栈:

var themeObservers = [];

8.在 App 中自定义主题更换的监听方法:

globalData: {
		theme: 'light', // dark
	},
	changeAllTheme (theme) {
		this.globalData.theme = theme;
		themeObservers.forEach((observer) => {
			observer(theme);
		})
	},
	onWatchChangeTheme (observer) {
		if (themeObservers.indexOf(observer) < 0) {
            themeObservers.push(observer);
        }
	},
	unWatchChangeTheme (observer) {
		var index = themeObservers.indexOf(observer);
		if (index > -1) {
            themeObservers.splice(index, 1);
        }
	}
0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago