android创建构建方法,Android 应用程序构建实战+原理精讲
轉載來自51cto:https://blog.51cto.com/15091291/2629464
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 實例
網站列表
v-for="site in info"
{{ site.name }}
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);
});
}
})
嘗試一下 ?
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 应用程序构建实战+原理精讲的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 评估指标_机器学习评估方法与评估指标总结
- 下一篇: Linux上下载chronyd安装包,如