npm install axios --save // 安装
<script>
import HomeHeader from './header'
import HomeSwiper from '@/components/Swiper'
import HomeNav from './nav'
import HomeRecommend from './recommend'
import axios from 'axios'
export default{
name: 'home',
components: {
HomeHeader,
HomeSwiper,
HomeNav,
HomeRecommend
},
data(){
return{
city:'北京',
swiper:[]
}
},
mounted() {
this.gethomeinfo()
},
methods:{
gethomeinfo(){
axios.get("/api/index.json").then(this.consolelog)
},
consolelog(data){
var json=data.data
if(json.ret){
const data=json.data;
this.city=data.city;
this.swiper=data.swiperSlides;
console.log (data);
}
}
}
}
</script>
网友评论