如何制作 Lightning Web 组件?
How to make a Lightning Web Components?
我需要使用此 Apex Class 制作 Lightning Web 组件,但我不知道如何将数据传递给 JS 和 HTML 以及如何创建该 lwc。我想制作一个 lwc,显示每次 lwc 组件为 used/called 时从特定电子邮件收到的每封电子邮件。也许做一个光环组件更好?我不知道。这是代码
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);
}
}
}
}
}
您需要按照 documented pathways 在 Lightning Web 组件中调用 Apex 方法。
您可以使用 imperative call or a wire method 来完成此操作。由于您的 Apex 方法不带参数,命令式调用可能是可行的方法。
我需要使用此 Apex Class 制作 Lightning Web 组件,但我不知道如何将数据传递给 JS 和 HTML 以及如何创建该 lwc。我想制作一个 lwc,显示每次 lwc 组件为 used/called 时从特定电子邮件收到的每封电子邮件。也许做一个光环组件更好?我不知道。这是代码
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);
}
}
}
}
}
您需要按照 documented pathways 在 Lightning Web 组件中调用 Apex 方法。
您可以使用 imperative call or a wire method 来完成此操作。由于您的 Apex 方法不带参数,命令式调用可能是可行的方法。