1.引入插件axios

<script src="./node_modules/axios/dist/axios.js"></script>

2.axios方法写在created函数体中

created() {
                axios.get('http://127.0.0.1:5500/db.json')
              .then(respons => this.axiosData = respons.data)
            }

3.完整版

created() {
            axios.get("http://127.0.0.1:5500/vue-01/db.json")
            .then((response)=>{
            console.log(response.data);
            this.msg=response.data
            })
            .catch((error)=>{
                console.log(error.message);
            })
            .finally(()=>{
                console.log("finally")
            })
        }

 

posted on 2019-10-19 18:28  宅到深夜  阅读(263)  评论(0)    收藏  举报