一、主地址:
//src/utils/config.jsimport axios from 'axios'axios.defaults.baseURL = 'http://192.168.14.49:5000';Vue.prototype.axios = axios; // 将主地址赋值绑定给 axios 方便不同页面发送请求export default Vue; //导出Vue
二、用法:
//.vue//在data中定义要循环的数组<script> export default { data() { return { tracks:[] } } }</script>/*需写在vue文件的script标签中,并写在mounted里面*/// 用then触发<script> export default { mounted(){ this.axios.get(`playlist/detail?id=${this.id}`).then(res=>{ this.tracks = res.data.playlist.tracks; console.log(this.tracks); }) }</script>
三、axios-get
parmas参数传递数据给后端
methods: { handlePrice(gt, lt) { console.log(gt, lt); this.$http({ url: "/goods/price", method: "get", params: { gt, lt } }).then(res => { this.goodsList = res.data.result; }); } }