美文网首页
Vue框架+axios使用详细教程

Vue框架+axios使用详细教程

作者: 糖醋鱼_ | 来源:发表于2021-01-12 16:04 被阅读0次
1、安装

npm install --save axios vue-axios
或 cnpm install --save axios vue-axios

2、在主文件 main.js 引入
import axios from 'axios'
import VueAxios from 'vue-axios'

Vue.use(VueAxios, axios)
3、在组件里使用

(1)推荐

    this.axios.get(api).then((response) => {
      console.log(response)
    })

(2)

    import Vue from 'vue'    //需要引入vue
    Vue.axios.get(api).then((response) => {
      console.log(response.data)
    })

(3)

    this.$http.get(api).then((response) => {
      console.log(response)
    })

相关文章

网友评论

      本文标题:Vue框架+axios使用详细教程

      本文链接:https://www.haomeiwen.com/subject/tlceaktx.html