[英]How to import the AWS SDK into Vue.JS
I have the AWS Javascript for Browsers SDK that's been configured from my AWS API Gateway endpoints. 我有从我的AWS API网关端点配置的AWS Javascript for Browsers SDK。
The readme says that I need to include the files and then reference like this: 自述文件说我需要包含文件,然后像这样引用:
<script type="text/javascript" src="apigClient.js"></script>
This file contains: 该文件包含:
var apigClientFactory = {};
apigClientFactory.newClient = function (config) {
var apigClient = { };
if(config === undefined) {
config = {
accessKey: '',
secretKey: '',
sessionToken: '',
region: '',
apiKey: undefined,
defaultContentType: 'application/json',
defaultAcceptType: 'application/json'
};
// Etc...
}
However I'm not sure how to do this in Vue.js. 但是我不知道如何在Vue.js中这样做。 I've set up a separate component which I think needs to import this file, but how do I do that? 我已经设置了一个单独的组件,我认为需要导入该文件,但我该怎么做?
There is nothing particular to know, really. 真的,没有什么特别要知道的。
I'm not sure this is the way to go with AWS SDK, but if you don't want to use a bundler, just assign the variable you want to export to the global window object. 我不确定这是使用AWS开发工具包的方法,但如果您不想使用捆绑器,只需将要导出的变量分配给全局窗口对象即可。 It should be available everywhere, including in your components. 它应该随处可用,包括在您的组件中。
If you want to use the newClient function outside, you can make apigClientFactory global. 如果要在外部使用newClient函数,可以使apigClientFactory全局化。
window.apigClientFactory = {};
apigClientFactory.newClient = function (config) {
// ...
}
So in your component you can create a new client, assuming that newClient() return the created client: 因此,在组件中,您可以创建一个新客户端,假设newClient()返回创建的客户端:
var myClient = window.apigClientFactory.newClient();
Or, if you want to keep a single AWS client through you whole app, make the client itself global instead. 或者,如果您希望通过整个应用程序保留单个AWS客户端,请将客户端本身设为全局。
var apigClientFactory = {};
apigClientFactory.newClient = function (config) {
// ...
}
window.myClient = apigClientFactory.newClient();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.