-
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);
- });
- }
- 方法一:直接在.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);
- });
- }
-
相关阅读:
Zepto swipe 无效(坑)
Zepto.js-Ajax 请求
Zepto.js-事件处理
excel 大文件解析原理实现
springboot 集成J2Cache
springboot 单元测试 指定启动类
springboot 解决 数字长度过长导致JS精度丢失问题
JS 基本操作
VUE 动态菜单管理
VUE router-view key 属性解释
-
原文地址:https://www.cnblogs.com/h-h-t/p/7906337.html
Copyright © 2020-2023
润新知