[Vue3.0]安装Ajax库 axios

  • 安装组件
# 进入项目目录
$ cd myweb
$ npm install --save --save-exact axios vue-axios


npm WARN ajv-keywords@3.4.1 requires a peer of ajv@^6.9.1 but none is installed. You must install peer dependencies yourself.
npm WARN bootstrap@4.4.1 requires a peer of jquery@1.9.1 - 3 but none is installed. You must install peer dependencies yourself.
npm WARN bootstrap@4.4.1 requires a peer of popper.js@^1.16.0 but none is installed. You must install peer dependencies yourself.

  • vue-axios@2.1.5
  • axios@0.19.2
    added 4 packages from 8 contributors in 11.461s

26 packages are looking for funding
run npm fund for details

  • 编辑main.js引入
import axios from 'axios'
import VueAxios from 'vue-axios'

Vue.use(VueAxios,axios)
  • js代码
<template>
  <div class="hello">
    <pre>{{content}}</pre>
  </div>
</template>

<script>
export default {
  name: 'HelloWorld',
  data () {
    return {
      content:""
    }
  },
  mounted() {
    this.axios.post("http://api.komavideo.com/new/list").then(body => {
      this.content = body.data;
    })
  }
}
</script>

[Vue3.0]安装Ajax库 axios

上一篇:【转】领略Java内部类的“内部”


下一篇:异步刷新