Method mapping through the title interpretation can also be clearly seen, is through the js call and the native method of the same name, in the native return data to return these data back to JS a method, the reason for doing so is weeX network requests can not meet the needs of our client network security and various configurations. To do this, first in WEEx, we write a network request file called fetch. Js, where we write all the methods:

const request = weex.requireModule('fetchJS'); Export function getListInfor {let dic = {page: "1", userID: "1234"}; return new Promise((resolve, reject) => { stream.fetch({ method: 'post', url: 'https://xxxxxxxxxxxxxxxxxxxxx', type: 'json', headers:{'Content-Type':'application/json'}, body: JSON.stringify(dic) }, (response) => { console.log('hello'+JSON.stringify(response.data)); Response resolve(response.data); }, () => {})})}Copy the code

Now that we have our JS method written, how do we map to the native method by calling this method? In native species we write like this:

.h file #import <Foundation/ foundation. h> #import "weexsdK.h" @interface WXEventModule: NSObject<WXModuleProtocol> @end. m file #import "wxEventModule. h" @implementation WXEventModule @synthesize weexInstance; WX_EXPORT_METHOD (@ the selector (the fetch: callback: progressCallback:)) / /!!! This method must be the same as my following oh, or you can search for this method in SKD, which provides several methods, must be the same as these methods name, Or write their own name system doesn't recognize - (void) the fetch (NSDictionary *) options callback (WXModuleKeepAliveCallback) callback progressCallback:(WXModuleKeepAliveCallback)progressCallback { [[RequestManager sharedInstance] wx_request:options Callback (@{@"data": callback(@{@"data":}) {finished:^(id result) { result}, false); }]; } / / ps: - (void)wx_request:(NSDictionary *)dic finished:(void(^)(id result))handler { NSString *url = dic[@"url"]; NSDictionary *bodyDic = dic[@"body"]; NSString *method = dic[@"method"]; NSURLRequest *request; If ([method isEqualToString: @ "get"]) {XXXXXX / / get the different Settings} else {XXXXXX different snake porridge} / / post / / this is the online request method, bloggers all their own way to the can, Don't obsess [self request: request requestCompletionHandler: ^ (NSMutableDictionary * dic, NSString *errorMsg) { handler(dic); }]; } // Last but not least, don't forget to register, not to mention basic bloggers, Not we can see the following links [WXSDKEngine registerModule: @ "fetchJS" withClass: NSClassFromString (@ "WXEventModule")];Copy the code

Weex – Custom Module

This js method must be used to tell you, do not know the situation is really difficult to consider:

import * as fetchRequest from '.. /network/fetch'; Request.getlistinfor (data =>{console.log(json.stringify (data))); this.listArray = data; });Copy the code

Above put the method mapping finished, in fact, also don’t trouble, which hook function and goback function worth digging, not very understand JS, vue may not understand, it doesn’t matter, slowly learn, weex learning road, with you.