zoukankan      html  css  js  c++  java
  • vue axios

    简单示例

    "dependencies": {
        "axios": "^0.18.0",
        "element-ui": "^2.4.11",
        "js-cookie": "^2.2.0",
        "vue": "^2.5.2",
        "vue-router": "^3.0.1"
      },
    devDependencies
    "mockjs": "^1.0.1-beta3",

    <script>
    import axios from 'axios'
    import mock from '@/mock/mock.js'
    export default {
      name: 'Home',
      methods: {
        testAxios() {
          axios.get('http://localhost:8080').then(res => { alert(res.data) })
        },
        getUser() {
          axios.get('http://localhost:8080/user').then(res => { alert(JSON.stringify(res.data)) })
        },
        getMenu() {
          axios.get('http://localhost:8080/menu').then(res => { alert(JSON.stringify(res.data)) })
        }
      }
    }
    </script>

    post请求及传参

    getUser() {
          axios({
            method: 'post',
            url: 'http://192.168.223.129:9051/dbm/dc/get',
            data: {
              token: '62947406',
              tag: 'service_id_running',
              key: 'esql_srv_01'
            },
            timeout: 1000,
    
          }).then(res => {
            let dt =res.data;
            let sts = dt.status;
            alert(dt.res);
            alert(sts);
          }).then(() => {
            alert(22);
            this.$axios({
              method: 'post',
              url: 'http://192.168.223.129:9051/dbm/dc/get',
              data: {
                token: '62947406',
                tag: 'service_id_running',
                key: 'esql_srv_01'
              },
              timeout: 1000,
    
            }).then(res => {
              let dt =res.data;
              let sts = dt.status;
              alert(dt.res);
              alert(sts);
            });
          }).catch(reason => {
            alert(reason);
          });
        },
  • 相关阅读:
    常见的兼容问题
    css3新增伪类
    完美的js运动框架
    C++ 常用宏
    多线程代码段 自清理线程
    寒假自学(十一)
    寒假自学(十)
    寒假自学(九)
    寒假自学(八)
    寒假自学(七)
  • 原文地址:https://www.cnblogs.com/perfei/p/13974451.html
Copyright © 2011-2022 走看看