Loading…

Byte/Toutiao/Douyin Mini Program

Table of contents on this page
# Release Notes The npm capability is supported starting from the basic library version 2.12.0 and the IDE version 3.1.1. For details, please see the official instructions: [https://microapp.bytedance.com/docs/zh-CN/mini-app/develop/framework/npm/](https://microapp.bytedance.com/docs/zh-CN/mini-app/develop/framework/npm/) So please make sure that your development tools are upgraded to 3.1.1 or above, and the basic library used is no lower than 2.12.0 # Add npm support Check whether the `package.json` file exists in the root directory of your mini program project. If it exists, it means that your mini program project already supports npm. Otherwise, you need to follow the following tutorial to add npm support: ```bash npm init ``` After the command is executed, make sure that the `package.json` file appears in the root directory, indicating success. Otherwise, check the above operations until success. # Install ```bash npm install apifm-ttapi ``` Run this command to install the latest version of the SDK with one click # Build The npm module installed by the mini program cannot be used directly. You need to build it first. You will be prompted to build successfully before you can use it!![](https://dcdn.it120.cc/yuque/0/2021/png/572726/1635564520285-1b2edb7f-c05a-4b55-a6ac-335f7f25406f.png) # use js file to load the SDK directly: ```javascript const WXAPI = require('apifm-ttapi') WXAPI.init('gooking') ``` `WXAPI.init('gooking')`This code can be executed globally once in the mini program and does not need to appear everywhere, so it is recommended to execute it in the mini program`app.js`File, just write it once.Then you can directly call any method of the SDK to read and operate your background data, for example: ```javascript WXAPI.banners().then(res => { if (res.code == 0) { this.setData({ banners: res.data }) } }) ``` Or: ```javascript const res = await WXAPI.banners() if (res.code == 0) { this.setData({ banners: res.data }) } ```