vuejs入门☞学习笔记--axios使用

1、安装axios插件

npm insatll axios --save

2、在main.js中引用

import axios from 'axios'
// 只能把axios挂载到vue的原型上
Vue.prototype.$axios = axios;

3、在App.vue中使用

export default {
  name: 'Index',
  data () {
    return {
      msg: 'hello'
    }
  },
  mounted () {
    this.$axios
      .get(
        '../../static/test.json'
      )
      .then(res => {
        this.msg = res.data
      })
      .catch(err => {
        alert(err)
      })
  }
}
发布了24 篇原创文章 · 获赞 6 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/Wutongyewan/article/details/97679109