vue2.0之axios使用详解(二)
来源:互联网 发布:视频cms 编辑:程序博客网 时间:2024/06/07 06:54
发了vue2.0之axios使用详解(一)后,有朋友问如何在实际项目中使用,下面把我平常用的两种方法分享下,自己在实际项目中总结的方法,有不好的地方还请指正,共同提高,谢谢!
方法一:直接在.vue文件中引入使用在.vue文件中使用<script> import axios from 'axios'; export default { name: 'news', data () { return { } }, methods: { getNewsFn(){ axios.get(this.dataURL + '/getNews').then((news) => { this.news = news.data; } ).catch((err) => { console.log(err); } ); } } }</script>方法二:注册为全局的函数首先在main.js文件中引入import axios from '../node_modules/axios';Vue.prototype.axios = axios;new Vue({ el: '#app', router, store, axios, echarts, template: '<App/>', components: { App }});其次在.vue文件中使用 defaultData(){ let _this = this; _this.axios.get('http://' + _this.$store.state.defaultHttp + '?action_type=comp_news&comp_id=' + _this.$store.state.compValue + '&offset=0&len=' + _this.pageNum, {}, { headers: {} }).then(function (response) { }).catch(function (response) { console.log(response); }); }
2 0
- vue2.0之axios使用详解(二)
- vue2.0之axios使用详解(二)
- vue2.0之axios使用详解(二)
- vue2.0之axios使用详解(一)
- vue2.0之axios使用详解(一)
- vue2.0之axios使用详解(一)
- vue2.0之axios使用详解(一)
- vue2.0之axios使用详解(一)
- vue2.0之axios使用详解
- vue2.0之axios使用详解
- vue2.0之axios使用详解(一)
- vue2.0之axios
- vue2.0数据请求之axios
- vue2 axios的使用
- vue2.0+vue-router2.0+axios+webpack开发webapp项目(二)
- vue2.0中Ajax库(axios)
- vue2.0 axios前后端数据处理
- vue2.0 axios前后端数据处理
- javascript的push和pop方法
- JQuery 的基础使用
- MIMO/SIMO/SISO
- fork 函数说明
- 【Struts2】struts2学习(3) 资源国际化
- vue2.0之axios使用详解(二)
- Android6.0权限处理封装
- Android中Canvas绘图之PorterDuffXfermode的坑
- swift代码之路(四)UICollectionView
- redhat7.0配置软raid
- mysql INSERT ... ON DUPLICATE KEY UPDATE语句
- POJ 2446 Chessboard(二分图-网格图构图)
- android网易顶部导航栏demo
- 建立j2se开发环境