我是vue.js的新手,我尝试从url接收列表。这里有一些问题: 1.我无法在main.js中定义axios,所以我可以在index.html中使用它(这个解决方案对我来说不起作用https://stackoverflow.com/a/51374448/9582441) 2.当我使用console.log(响应)时,响应为空,因此请求尚未完成
我安装了axios,vue扔了vue-cli
main.js
import Vue from 'vue'
import App from './App.vue'
import axios from 'axios'
import VueAxios from 'vue-axios'
Vue.use(VueAxios, axios);
new Vue({
el: '#app',
render: h => h(App)
})
的index.html
<template>
<div id="app">{{ info }}</div>
</template>
<script>
export default {
name: "app",
data() {
return {
info: null
};
},
mounted() {
Vue.axios
.get("https://dog.ceo/api/breeds/list/all"
)
.then(response => (this.info = response));
console.log(response);
}
};
所以我只是想收到一个列表并以某种方式连接axios
this.axios
解决方案是使用
this.axios