如何制作Lightning Web组件



我需要用这个Apex类制作一个Lightning Web组件,但我不知道如何将数据传递给JS和HTML,以及如何创建lwc。我想制作一个lwc,每次使用/调用lwc组件时,都会显示从某封电子邮件收到的每封电子邮件。也许做Aura组件更好?我不知道。这是代码

public with sharing class Gmail {
public with sharing class GMResponseMessages {
public Integer resultSizeEstimate;
public GMThread[] messages;
}

public with sharing class GMThread {
public String id;
public String threadId;
}

public with sharing class GMMessage {
public String id;
public String threadId;
public String[] labelIds;
public String snippet;
public String historyId;
public String internalDate;
public GMMessagePart payload;
public String sizeEstimate;
public String raw;  
}

public with sharing class GMMessagePart {
public String partId;
public String mimeType;
public String filename;
public Header[] headers;
public GMMessagePartBody[] body;
public GMMessagePart[] parts;  
}

public with sharing class Header {
public String name;
public String value;
}

public with sharing class GMMessagePartBody {
public String attachmentId;
public String superinteger;
public String data;
}

@AuraEnabled
public static void getGmail_API() {
//GET https://gmail.googleapis.com/gmail/v1/users/{userId}/messages/{id}
Http http = new Http();
HTTPResponse response;
HttpRequest request;
String userEmail = 'myemail@gmail.com';

request = new HttpRequest();
request.setMethod('GET');
request.setEndpoint('callout:Gmail_API/gmail/v1/users/myemail@gmail.com/messages?q=from:othermail@mail.it');

response = http.send(request); 
System.debug('START');
System.debug(response.getStatusCode());

if(response.getStatusCode() == 200) {
JSONParser parser = JSON.createParser(response.getBody());
System.debug(parser);
GMResponseMessages jsonResponse = (GMResponseMessages)JSON.deserialize(response.getBody(), GMResponseMessages.class);
System.debug(jsonResponse); 

for(GMThread thread: jsonResponse.messages){
System.debug('THREAD FOR');
System.debug(thread);
Http httpMsg = new Http();
HTTPResponse responseMsg;
HttpRequest requestMsg;
requestMsg = new HttpRequest();
requestMsg.setMethod('GET');
requestMsg.setEndpoint('callout:Gmail_API/gmail/v1/users/myemail@gmail.com/messages/' + thread.id);
responseMsg = httpMsg.send(requestMsg); 
if(responseMsg.getStatusCode() == 200) {
GMMessage jsonResponseMsg = (GMMessage)JSON.deserialize(responseMsg.getBody(), GMMessage.class);
System.debug(jsonResponseMsg);

}
}
}
}

}

您需要遵循文档中的路径来调用Lightning Web组件中的Apex方法。

您可以通过使用命令式调用或关联方法来实现这一点。由于您的Apex方法不带参数,因此命令式调用可能是可行的。

最新更新