码迷,mamicode.com
首页 > 其他好文 > 详细

Vue发送请求

时间:2018-06-03 01:03:54      阅读:971      评论:0      收藏:0      [点我收藏+]

标签:curl   www.   php   pread   ber   rmi   turn   mission   使用   

可以试试玩ajax请求,个人觉得axios用Promise包装了下,代码美观

axios请求使用方法; https://www.npmjs.com/package/axios-es6

1.npm install axios -save,

mian.js中引入

import Axios from ‘axios‘

Vue.prototype.$axios = Axios

2.发送请求,遍历数据

<template>
<div>
<ul>
<li v-for="data in newsData">
<p>{{data.title}}</p>
<img :src="data.img"/>
<p>{{data.content}}</p>
</li>
</ul>
</div>
</template>

<script>
export default {
name: ‘httpData‘,
data() {
return {
newsData:[]
}
},
created() {
const ulr2 = ‘http://www.wwtliu.com/sxtstu/news/juhenews.php‘
const ulr = ‘http://www.wwtliu.com/sxtstu/blueberrypai/getIndexBanner.php‘
let param = {
type:‘junshi‘,
count:30
}
this.$axios(ulr,{params:param}).then(res => {
console.log(res.data.banner)
this.newsData = res.data.banner
}).catch(err => {
console.time(err)
})
}
}
</script>

<style>

</style>

post请求 摘自官网

axios.post(‘/user{
    firstName‘Fred,
    lastName‘Flintstone
  })
  .then(function (response{
    console.log(response);
  })
  .catch(function (response{
    console.log(response);
  });

A.      Performing multiple concurrent requests

function getUserAccount({
  return axios.get(‘/user/12345);
}
 
function getUserPermissions({
  return axios.get(‘/user/12345/permissions);
}
 
axios.all([getUserAccount()getUserPermissions()])
  .then(axios.spread(function (acctperms{
    // Both requests are now complete
  }));

 

Vue发送请求

标签:curl   www.   php   pread   ber   rmi   turn   mission   使用   

原文地址:https://www.cnblogs.com/qiyc/p/9127564.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!