Skip to content

Commit cbc9150

Browse files
SupermanSuperman
authored andcommitted
update request
1 parent a263b1f commit cbc9150

File tree

5 files changed

+144
-1
lines changed

5 files changed

+144
-1
lines changed

app/components/example/Main.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
<Button class="btn btn-primary m-t-20" text="下拉刷新" @tap="refresh" />
2727
<Button class="btn btn-primary m-t-20" text="下拉刷新❤新" @tap="refreshNew" />
2828
<Button class="btn btn-primary m-t-20" text="触摸事件" @tap="touch" />
29+
<Button class="btn btn-primary m-t-20" text="请求" @tap="request" />
2930
</StackLayout>
3031
<!-- </GridLayout> -->
3132
</ScrollView>
@@ -50,6 +51,7 @@ import Animate from "./animate";
5051
import Refresh from "./refresh";
5152
import RefreshNew from "./refreshNew";
5253
import Touch from "./touch";
54+
import Request from "./request";
5355
5456
export default {
5557
data () {
@@ -59,6 +61,9 @@ export default {
5961
},
6062
mounted () { },
6163
methods: {
64+
request: function () {
65+
this.$navigateTo(Request);
66+
},
6267
touch: function () {
6368
this.$navigateTo(Touch);
6469
},

app/components/example/request.vue

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
<template>
2+
<Page>
3+
<ActionBar class="action-bar" title="Hello">
4+
<NavigationButton text="Go Back" android.systemIcon="ic_menu_back" @tap="$navigateBack" />
5+
</ActionBar>
6+
<GridLayout colums="*" rows="*">
7+
<!-- <Label class="message" :text="msg" col="0" row="0" /> -->
8+
<Button class="request" text="start request" @tap="onButton" />
9+
</GridLayout>
10+
</Page>
11+
</template>
12+
13+
<script>
14+
import app from '../App';
15+
import { Http } from '@billow/nsv-http';
16+
import { isAndroid } from 'platform';
17+
import { getString } from 'application-settings'; // Example Only
18+
// import { log } from 'util';
19+
//import * as http from 'http';
20+
export default {
21+
data() {
22+
return {
23+
msg: 'Hello World! '
24+
};
25+
},
26+
methods: {
27+
onButton: function() {
28+
console.log('000');
29+
let http = new Http({
30+
// Configure a base url for all requests
31+
baseUrl: 'https://www.easy-mock.com',
32+
33+
// Example headers, typically this is what we use when interacting with a Laravel Passport API.
34+
headers: {
35+
'Content-Type': 'application/json',
36+
Accept: 'application/json;charset=utf-8',
37+
'Accept-Encoding': isAndroid ? 'identity' : 'gzip, deflate, br', // Android requests fail when the server is gzipping responses, this is a work around.
38+
'X-Requested-With': 'XMLHttpRequest',
39+
Authorization: 'Bearer ' + getString('token', '')
40+
}
41+
});
42+
http.post(
43+
'/mock/5d60c006f81908124e0fcc23/example/upload',
44+
{},
45+
function(res) {
46+
console.log('返回的数据是:', res);
47+
console.log('返回的内容是:', res.content);
48+
console.log('拿到数据:', res.content.data.img);
49+
},
50+
function(err) {
51+
console.log('错误是:', err);
52+
}
53+
);
54+
55+
//console.log('hhhhhs', http);
56+
// console.log('hhhhhs', isAndroid);
57+
// var formdata = new FormData();
58+
// //可以通过append()方法来追加数据
59+
// formdata.append('name', 'laotie');
60+
// let content = {
61+
// title: 'foos',
62+
// body: 'bar',
63+
// userId: 1
64+
// };
65+
// let header = {
66+
// 'Content-type': 'application/json; charset=UTF-8'
67+
// };
68+
// http.request({ method: 'post', url: 'https://jsonplaceholder.typicode.com/posts', content: JSON.stringify(content), header: header })
69+
// .then(response => {
70+
// console.dir('HTTP RESPONSE RECEIVED: ' + JSON.stringify(response));
71+
// response.content = response.content.toJSON();
72+
// console.dir('HTTP RESPONSE RECEIVED: ' + response.statusCode);
73+
// console.dir(response.content);
74+
// //return this.succeeded(response.statusCode) ? success(response) : failure(response);
75+
// })
76+
// .catch(error => {
77+
// console.log('HTTP REQUEST FAILED: ' + error);
78+
// //return failure(error);
79+
// });
80+
81+
// console.log('hhhhhs', isAndroid);
82+
// var formdata = new FormData();
83+
// //可以通过append()方法来追加数据
84+
// formdata.append('name', 'laotie');
85+
// let content = {
86+
// // title: 'foos',
87+
// // body: 'bar',
88+
// // userId: 1
89+
// };
90+
// let header = {
91+
// 'Content-type': 'application/json; charset=UTF-8'
92+
// };
93+
// http.request({ method: 'post', url: 'https://www.easy-mock.com/mock/5d60c006f81908124e0fcc23/example/upload', content: JSON.stringify(content), header: header })
94+
// .then(response => {
95+
// console.dir('HTTP RESPONSE RECEIVED: ' + JSON.stringify(response));
96+
// response.content = response.content.toJSON();
97+
// console.dir('HTTP RESPONSE RECEIVED: ' + response.statusCode);
98+
// console.dir(response.content);
99+
// //return this.succeeded(response.statusCode) ? success(response) : failure(response);
100+
// })
101+
// .catch(error => {
102+
// console.log('HTTP REQUEST FAILED: ' + error);
103+
// //return failure(error);
104+
// });
105+
}
106+
}
107+
};
108+
</script>
109+
110+
<style scoped>
111+
ActionBar {
112+
background-color: #53ba82;
113+
color: #ffffff;
114+
}
115+
116+
.message {
117+
vertical-align: center;
118+
text-align: center;
119+
font-size: 20;
120+
color: #333333;
121+
}
122+
.request {
123+
color: green;
124+
font-size: 24px;
125+
}
126+
</style>

package-lock.json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"devDependencies": {
3737
"@babel/core": "^7.0.0",
3838
"@babel/preset-env": "^7.0.0",
39+
"@billow/nsv-http": "^1.0.5",
3940
"babel-loader": "^8.0.2",
4041
"babel-traverse": "6.26.0",
4142
"babel-types": "6.26.0",
@@ -51,8 +52,8 @@
5152
"nativescript-worker-loader": "~0.9.0",
5253
"node-sass": "^4.9.2",
5354
"sass-loader": "^7.1.0",
54-
"uglifyjs-webpack-plugin": "~1.2.7",
5555
"terser-webpack-plugin": "^1.1.0",
56+
"uglifyjs-webpack-plugin": "~1.2.7",
5657
"vue-loader": "^15.7.1",
5758
"webpack": "^4.16.4",
5859
"webpack-bundle-analyzer": "~2.13.1",

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,11 @@
649649
lodash "^4.17.13"
650650
to-fast-properties "^2.0.0"
651651

652+
"@billow/nsv-http@^1.0.5":
653+
version "1.0.5"
654+
resolved "https://registry.yarnpkg.com/@billow/nsv-http/-/nsv-http-1.0.5.tgz#06dd7f819002122949c8f7b15eacc90e9d4108fb"
655+
integrity sha512-N7Vn8dtnQtL+OI2Qh6YkK6MVRQXd4qjb89O4bLst4zxS219FZhwS3OvMRwCqAoAwmQM4m2kNgNgditqLO8sUsg==
656+
652657
"@types/node@^7.0.18":
653658
version "7.10.7"
654659
resolved "https://registry.yarnpkg.com/@types/node/-/node-7.10.7.tgz#8604623912010235185f1166c7a5a9aa7de9fcd8"

0 commit comments

Comments
 (0)