美文网首页
axios的基本使用

axios的基本使用

作者: 小沈新手 | 来源:发表于2018-11-19 22:59 被阅读20次

    一、安装

    cd 项目的目录

    npm install --save --save-exact axios vue-axios

    vue-axios可选择的安装,推荐安装

    二、使用 在main.js文件加入下面代码进行引入

    improt axios from 'axios'

    improt axios from 'VueAxios' from ''vueaxios

    Vue.use (VueAxios,axios)

    三、在具体的.vue中使用如下

    <template>

    <div>

      <pre>

        {{content}}

      </pre>

    </div>

    </template>

    <script>

    export default {

      name: 'Test',

      data(){

        return {

          content:""

        };

      },

      mounted(){//界面启动运行,估计是vue的生命周期

      this.axios.post("http://api.komavideo.com/news/list").then(body=>{

        this.content=body.data;

      });

      }

    }

    </script>

    <!-- Add "scoped" attribute to limit CSS to this component only -->

    <style >

    </style>

    运行效果:

    运行效果

    这样就获取到了接口的数据

    相关文章

      网友评论

          本文标题:axios的基本使用

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