<?php
header('Content-Type: application/json');
header('Access-Control-Allow-Origin:*');//允许所有来源访问
header('Access-Control-Allow-Method:POST,GET');//允许访问的方式
?>
{"status":0,"data":[
{"url":1,"img":"http://pic.rmb.bdstatic.com/96a604a50915109340b0e4a1b7271822.jpeg"},
{"url":2,"img":"https://p1.ssl.qhimg.com/dr/270_500_/t01aef57ee9046b1971.jpg?size=1024x681"},
{"url":3,"img":"https://p1.ssl.qhimg.com/dr/220__/t017211a4291dc576c7.jpg"}
]
}
头部一定要加,缺一不可,前面是json格式,后面是 跨域
vue测试,注意
import Vue from ‘vue’
import VueResource from ‘vue-resource’
Vue.use(VueResource);
Vue.http.options.root = ‘http://baixiu.dev/’;
getLunbotu() {
this.$http.get("api/getLunbo.php").then(result => {
if(result.body.status === 0){
console.log(result.body.data);
this.lunbotuList = result.body.data;
}else{
console.log("轮播图加载失败");
}
});
},