zoukankan      html  css  js  c++  java
  • vue2.0+++axios的使用方法

    1. 方法一:直接在.vue文件中引入使用  
    2.   
    3. 在.vue文件中使用  
    4. <script>  
    5.   import axios from 'axios';  
    6.   export default {  
    7.     name: 'news',  
    8.     data () {  
    9.       return {  
    10.       }  
    11.     },  
    12.     methods: {  
    13.       getNewsFn(){  
    14.         axios.get(this.dataURL + '/getNews').then((news) => {  
    15.             this.news = news.data;  
    16.           }  
    17.         ).catch((err) => {  
    18.             console.log(err);  
    19.           }  
    20.         );  
    21.       }  
    22.     }  
    23.   }  
    24. </script>  
    25.   
    26.   
    27. 方法二:注册为全局的函数  
    28.   
    29. 首先在main.js文件中引入  
    30. import axios from '../node_modules/axios';  
    31.   
    32. Vue.prototype.axios = axios;  
    33.   
    34. new Vue({  
    35.   el: '#app',  
    36.   router,  
    37.   store,  
    38.   axios,  
    39.   echarts,  
    40.   template: '<App/>',  
    41.   components: { App }  
    42. });  
    43. 其次在.vue文件中使用  
    44.   defaultData(){  
    45.         let _this = this;  
    46.         _this.axios.get('http://' + _this.$store.state.defaultHttp + '?action_type=comp_news&comp_id=' + _this.$store.state.compValue + '&offset=0&len=' + _this.pageNum, {}, {  
    47.             headers: {}  
    48.         }).then(function (response) {  
    49.               
    50.         }).catch(function (response) {  
    51.             console.log(response);  
    52.         });  
    53.     }          
    [javascript] view plain copy
     
     
    1. 方法一:直接在.vue文件中引入使用  
    2.   
    3. 在.vue文件中使用  
    4. <script>  
    5.   import axios from 'axios';  
    6.   export default {  
    7.     name: 'news',  
    8.     data () {  
    9.       return {  
    10.       }  
    11.     },  
    12.     methods: {  
    13.       getNewsFn(){  
    14.         axios.get(this.dataURL + '/getNews').then((news) => {  
    15.             this.news = news.data;  
    16.           }  
    17.         ).catch((err) => {  
    18.             console.log(err);  
    19.           }  
    20.         );  
    21.       }  
    22.     }  
    23.   }  
    24. </script>  
    25.   
    26.   
    27. 方法二:注册为全局的函数  
    28.   
    29. 首先在main.js文件中引入  
    30. import axios from '../node_modules/axios';  
    31.   
    32. Vue.prototype.axios = axios;  
    33.   
    34. new Vue({  
    35.   el: '#app',  
    36.   router,  
    37.   store,  
    38.   axios,  
    39.   echarts,  
    40.   template: '<App/>',  
    41.   components: { App }  
    42. });  
    43. 其次在.vue文件中使用  
    44.   defaultData(){  
    45.         let _this = this;  
    46.         _this.axios.get('http://' + _this.$store.state.defaultHttp + '?action_type=comp_news&comp_id=' + _this.$store.state.compValue + '&offset=0&len=' + _this.pageNum, {}, {  
    47.             headers: {}  
    48.         }).then(function (response) {  
    49.               
    50.         }).catch(function (response) {  
    51.             console.log(response);  
    52.         });  
    53.     }          
  • 相关阅读:
    vector.clear()无法释放内存的对策
    www.wangtam.com
    VC 控件的字体控制 若将字体设置成“宋体、仿宋—GB2312、隶书、幼圆”中的某一字体时,需将lfCharSet设置成GB2312—CHARSET才使设置的字体有效
    CPU使用率 武胜
    MySQL数据类型 转 武胜
    按小时统计的语句 转 武胜
    MYSQL 行转成列 转 武胜
    推荐一个 开源C#股票软件 武胜
    WCF传输泛型 List 对象 转 武胜
    WCF 传输大数据的问题 转 武胜
  • 原文地址:https://www.cnblogs.com/h-h-t/p/7906337.html
Copyright © 2011-2022 走看看