[英]How to make a Lightning Web Components?
I need to make a Lightning Web Components with this Apex Class but I don't know how to pass the data to the JS and the HTML and how to create that lwc.我需要使用此 Apex Class 制作 Lightning Web 组件,但我不知道如何将数据传递给 JS 和 HTML 以及如何创建该 lwc。 I want to make a lwc that shows every email received from a certain email every time that lwc components is used/called.
我想制作一个 lwc,显示每次使用/调用 lwc 组件时从某个 email 收到的每个 email。 Maybe is better to do an Aura Component?
也许做一个光环组件更好? I don't know.
我不知道。 Here's the code
这是代码
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);
}
}
}
}
} }
You'll need to follow the documented pathways to call an Apex method in a Lightning Web Component.您需要按照记录的路径在 Lightning Web 组件中调用 Apex 方法。
You can do this by using an imperative call or a wire method .您可以通过使用命令式调用或连线方法来做到这一点。 Since your Apex method takes no parameters, an imperative call is likely the way to go.
由于您的 Apex 方法不带参数,因此命令式调用可能是 go 的方式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.