Vue axios发送Http请求

axios

  1.cnpm install axios --save
  2.在vue文件中引入,import Axios from 'axios'
  3.使用,Axios.get(url).then((res)=>{}).catch((err)=>{})

<template>
  <div id="app">
    <div v-html="htmlValue"></div>
  </div>
</template>

<script>
import Axios from "axios";
export default {
  name: "app",
  data() {
    return {
      flag: true,
      htmlValue: ""
    };
  },
  methods: {
    getData() {
      Axios.post(`http://api2.cpf360.com/api/auth/login`)
        .then(res => {
          console.log(res)
          this.htmlValue=res.data
        })
        .catch(err => {});
    }
  },
  mounted() {
    this.getData();
  }
};
</script>

<style lang="scss">
</style>

猜你喜欢

转载自www.cnblogs.com/chenyishi/p/9160776.html