vue 接口统一管理
在外部创建一个API文件夹,然后创建一个API.js 例如
const filmbanner = 'api/billboard/home?__t=1498823077473'; const filmlist = 'api/film/now-playing?page=1&count=7'; const filmlist2 = 'api/film/coming-soon?page=1&count=7'; const address = 'api/city?__t=1498876411101'; const Performance = 'schedule?__t=1499234856430&pageSize=6&pageNumber=1&sortKey=sortSalesCount&sortType=desc&isMultiSku=1'; const mall = 'ad/list'; export default { filmbannerApi: filmbanner, filmlistApi:filmlist, filmlist2Api:filmlist2, addressApi:address, PerformanceApi:Performance, MallApi:mall }
在项目文件中引入使用
import api from '../../../common/api';
在项目文件中请求
this.$http.get(api.filmlistApi) .then((response)=>{ console.log(response.data.data.films) this.sdata = response.data.data.films console.log(this.sdata) //成功后关闭加载 this.$refs.loadmore.onTopLoaded(); })