Vue vue-resource发送Http请求

vue-resource

  1.cnpm install vue-resource --save
  2.在main.js中import VueResource from 'vue-resource'
  3.在main.js中Vue.use(VueResource)
  4.在组件中使用this.$http.get(url).then((response)=>{},(err)=>{})

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

<script>
import Home from "./components/Home.vue";
export default {
  name: "app",
  data() {
    return {
      flag: true,
      htmlValue: ""
    };
  },
  methods: {
    getData() {
      this.$http.post(`http://360.com/api/auth/login`).then(
        res => {
          console.log(res);
          this.htmlValue = res.body;
        },
        err => {}
      );
    }
  },
  mounted(){
    this.getData();
  }
};
</script>

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

猜你喜欢

转载自www.cnblogs.com/chenyishi/p/9160731.html
今日推荐