AXIOS 本质上等同于 JSON 传值
1. 引用
- // 引入 axios
- import Axios from 'axios'
- // 将 axios 挂载到 vue 原型上
- Vue.prototype.$https = Axios
- // 设置公共的 url
- Axios.defaults.baseURL = 'https://www.luffycity.com/api/v1/';
引用
2. 使用
- // 获取 分类列表的数据
- getCategoryList(){
- this.$https.get('course_sub/category/list/')
- .then((res)=>{
- console.log(res);
- var data = res.data;
- if(data.error_no === 0){
- this.categoryList = data.data;
- let obj = {
- id:0,
- name:'全部',
- category:0
- }
- this.categoryList.unshift(obj);
- // 数组 删除任意一个指定的元素
- // 指定数组中的索引 删除指定的元素 数组. splice(起始位置, 删除的个数)
- }
- })
- .catch((err)=>{
- console.log('获取列表失败',err)
- })
- },
需要在后面 created() 调用
3.
本质上, 通过挂载的方式进行全局的使用
挂载. get()
- ,then(function(response))
- .catch(function(response))
最终赋值的方式获取结果
来源: http://www.bubuko.com/infodetail-2873136.html