Loading…

Vue develops web or h5 applications

["Online Walkthrough"](https://bi.cool/project/m5vDU78/embed?bi-active-file=Banner.vue) # Install ```bash npm install apifm-webapi ``` Run this command to install the latest version of the SDK with one click # use ## Globally load SDK Open the `main.js` file and initialize the SDK globally ```javascript import WEBAPI from 'apifm-webapi' WEBAPI.init('gooking') Vue.prototype.$wxapi = WEBAPI ``` ## Call methods in SDK There are two ways to call the interface: ### Method 1 No need to introduce, call directly: ```javascript this.$wxapi.banners().then(res => { if (res.code == 0) { this.setData({ banners: res.data }) } }) ``` Or: ```javascript const res = await this.$wxapi.banners() if (res.code == 0) { this.setData({ banners: res.data }) } ``` ### Method 2 js file to load the SDK directly: ```javascript const WXAPI = require('apifm-webapi') ``` At this time, there is no need for `WEBAPI.init('gooking')`, because it has been set globally. ```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 }) } ``` # Open source reference [https://github.com/gooking/vueMinishop](https://github.com/gooking/vueMinishop)[Code Cloud Mirror:][https://gitee.com/javazj/vueMinishop](https://gitee.com/javazj/vueMinishop)