可以试试玩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请求 摘自官网
A. Performing multiple concurrent requests
原文:https://www.cnblogs.com/qiyc/p/9127564.html