Home  >  Article  >  WeChat Applet  >  Share example tutorials on mini program development and calling interfaces

Share example tutorials on mini program development and calling interfaces

零下一度
零下一度Original
2017-05-27 14:22:584573browse

Here is a simple example to illustrate the WeChat appletInterfaceCall:

First look at the effect:
Share example tutorials on mini program development and calling interfaces
Share example tutorials on mini program development and calling interfaces

This is the true appearance of the mini program, and the experience is somewhat similar to the native APP.


JSONData configuration:

{
  "navigationBarBackgroundColor": "#ffffff",
  "navigationBarTextStyle": "black",
  "navigationBarTitleText": "萌店商品详情",
  "backgroundColor": "#eeeeee",
  "backgroundTextStyle": "light"}

JS code:

 wx.request({
                url: 'http://m.vd.cn/api/tuan/TuanGuide_api', //仅为示例,并非真实的接口地址
                data: {
                    code:"oneyuan"  
                },
                method: "POST",
                header: {                    "Content-Type": "application/x-www-form-urlencoded"  //post
                },
                complete: function( res ) {
                    that.setData( {
                        oneyuandata: res.data.data
                    });                    if( res == null || res.data == null ) {
                        reject(new Error('网络请求失败'))
                    }
                },
                success: function(res) {
                    if(res.data.code ==0){
                        resolve(res)

                    }
                }
            })

Here is a brief explanation of JS, WCSS and WXML code Not offered!


url:这个是要请求的接口地址
data:一个入参
method:请求方式,如果是POST请求必须按上面写,默认是get请求,不用处理。
complete:页面请求完成后的方法,通过that.setData将数据传递给WXML页面。
success:页面加载成功后的执行方法。

[Related recommendations]

1. How to add a custom menu through http request?

2. Red envelope interface development example code for small program

3. Simple example code for small program development

The above is the detailed content of Share example tutorials on mini program development and calling interfaces. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn