Android 应用程序构建实战+原理精讲
download: Android 应用程序构建实战+原理精讲
new Vue({
el: '#app',
data () {
return {
info: null
}
},
mounted () {
axios
.get('https://www.runoob.com/try/ajax/json_demo.json')
.then(response => (this.info = response))
.catch(function (error) { // 请求失败处理
console.log(error);
});
}
})
尝试一下 »
使用 response.data 读取 JSON 数据:
GET 实例
<div id="app">
<h1>网站列表</h1>
<div
v-for="site in info"
{{ site.name }}
</div>
</div>
<script type = "text/javascript">
new Vue({
el: '#app',
data () {
return {
info: null
}
},
mounted () {
axios
.get('https://www.runoob.com/try/ajax/json_demo.json')
.then(response => (this.info = response.data.sites))
.catch(function (error) { // 请求失败处理
console.log(error);
});
}
})
</script>
尝试一下 »
GET 方法传递参数格式如下:
传递参数说明
// 直接在 URL 上添加参数 ID=12345
axios.get('/user?ID=12345')
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
// 也可以通过 params 设置参数:
axios.get('/user', {
params: {
ID: 12345
}
})
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
POST 方法
POST 实例
new Vue({
el: '#app',
data () {
return {
info: null
}
},
mounted () {
axios
.post('https://www.runoob.com/try/ajax/demo_axios_post.php')
.then(response => (this.info = response))
.catch(function (error) { // 请求失败处理
console.log(error);
});
}
})
尝试一下 »
POST 方法传递参数格式如下:
传递参数说明
axios.post('/user', {
firstName: 'Fred', // 参数 firstName
lastName: 'Flintstone' // 参数 lastName
})
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
执行多个并发请求
实例
function getUserAccount() {
return axios.get('/user/12345');
}
function getUserPermissions() {
return axios.get('/user/12345/permissions');
}
axios.all([getUserAccount(), getUserPermissions()])
.then(axios.spread(function (acct, perms) {
// 两个请求现在都执行完成
}));
axios API
可以通过向 axios 传递相关配置来创建请求。
实例
axios(config)
// 发送 POST 请求
axios({
method: 'post',
url: '/user/12345',
data: {
firstName: 'Fred',
lastName: 'Flintstone'
}
});
// GET 请求远程图片
axios({
method:'get',
url:'http://bit.ly/2mTM3nY',
responseType:'stream'
})
.then(function(response) {
response.data.pipe(fs.createWriteStream('ada_lovelace.jpg'))
});
axios(url[, config])
// 发送 GET 请求(默认的方法)
axios('/user/12345');
请求方法的别名
为方便使用,官方为所有支持的请求方法提供了别名,可以直接使用别名来发起请求:
axios.request(config)
axios.get(url[, config])
axios.delete(url[, config])
axios.head(url[, config])
axios.post(url[, data[, config]])
axios.put(url[, data[, config]])
axios.patch(url[, data[, config]])
- Android 应用程序构建实战+原理精讲
- 图解Android应用程序构建原理
- Android应用程序构建原理
- 【Android】Android应用程序构建原理
- Android培训实战教程之应用程序内存优化
- 在Windows Azure上为iOS、 Android 和 Windows Phone构建可扩展的移动应用程序
- Node.js项目实战-构建可扩展的Web应用(第一版):9 WebSocket,Socket.IO和DerbyJS的实时应用程序
- Android媒体应用(四)--构建音频应用程序
- 在Windows Azure上为iOS、 Android 和 Windows Phone构建可扩展的移动应用程序
- (Android实战)AsyncTask和Handler两种异步方式实现原理和优缺点比较
- 【转】android应用程序的安装方式与原理
- 从0开始构建你的api网关--Spring Cloud Gateway网关实战及原理解析
- Android系统在新进程中启动自定义服务过程(startService)的原理分析、Android应用程序绑定服务(bindService)的过程源代码分析
- 如何构建Android MVVM应用程序
- Android在WebView上构建Web应用程序
- 跟Google学习Android开发-起始篇-构建你的第一个应用程序(1)
- android应用程序运行原理-04
- Android应用程序组件Content Provider在应用程序之间共享数据的原理分析
- TQ210搭载Android4.0.3系统构建之BEEP从驱动到HAL到JNI到应用程序(上层应用篇)
- 使用组件构建Android应用程序