|
| 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> |
0 commit comments