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);
      });
    },

 

posted @ 2020-11-14 19:47  方诚  阅读(69)  评论(0编辑  收藏  举报