前端向后端调用接口的方式
传统方式:
axios(常用)
前提是安装了axios
main.js中引用
import axios from axios Vue.prototype.$http = axios
get方式:
httpGet(){ this.$http.get(apis/webapi/index/product) .then( (res) => { this.subnav=res.data; }) }
post方式:
httpPost(){ this.$http.post(apis/webapi/index/product,{id:id}) .then( (res) => { this.subnav=res.data; }) }
新方式:
接口由URL和HTTP方法构成,URL为接口的地址,HTTP方法指的是GET, PUT, DELETE等等传输方式。
GET方式:
axios.get().then().catch()
注:get方式传参数可以直接跟在url后面,也可以通过param对象传
POST方式:
axios.post().then().catch()
注:post方式传参必须用对象传
