-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: webpack-plugin-demo add network example
- Loading branch information
Showing
6 changed files
with
88 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
examples/webpack-plugin-demo/entry/src/main/ets/default/pages/network.ets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import axios from 'axios' | ||
import {LambdaClient, InvokeCommand} from "@aws-sdk/client-lambda"; | ||
import {CognitoIdentityClient} from "@aws-sdk/client-cognito-identity"; | ||
import {fromCognitoIdentityPool} from "@aws-sdk/credential-provider-cognito-identity"; | ||
|
||
@Entry | ||
@Component | ||
struct Network { | ||
@State response: string = '' | ||
|
||
build() { | ||
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, | ||
justifyContent: FlexAlign.Center }) { | ||
Text('OpenHarmony Network Demo') | ||
.fontSize(20) | ||
.fontWeight(FontWeight.Bold) | ||
Button('Use Axios').onClick(() => { | ||
this.response = 'request...' | ||
axios.get('https://www.openharmony.cn/sig') | ||
.then((res) => { | ||
console.log('---------') | ||
console.log(res.data) | ||
this.response = res.statusText | ||
}); | ||
}) | ||
|
||
Button('Use fetch').onClick(() => { | ||
this.response = 'request...' | ||
fetch('https://www.openharmony.cn/sig') | ||
.then(res => { | ||
console.log('-----------') | ||
console.log(res.data) | ||
this.response = res.statusText; | ||
}); | ||
}) | ||
|
||
Button('Use aws-sdk').onClick(() => { | ||
this.response = 'request aws...' | ||
const REGION = "us-west-2" | ||
const client = new LambdaClient({ | ||
region: REGION, | ||
credentials: fromCognitoIdentityPool({ | ||
client: new CognitoIdentityClient({ region: REGION }), | ||
identityPoolId: 'us-west-2:e88b2309-dcc2-4ea6-a5a9-1cd4b453e7b7' }) | ||
}); | ||
const params={ | ||
FunctionName: "hello", | ||
InvocationType: "RequestResponse", | ||
LogType: "None" | ||
} | ||
client.send(new InvokeCommand(params)).then( | ||
(data) => { | ||
this.response = new TextDecoder('utf-8').decode(data.Payload) | ||
}, | ||
(error) => { | ||
this.response = JSON.stringify(error) | ||
} | ||
); | ||
}) | ||
|
||
Text(this.response) | ||
.fontSize(16) | ||
} | ||
.width('100%') | ||
.height('100%') | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters