【问题标题】:VUE.JS Recieve a json file from url via axios in webpack-simpleVUE.JS 通过 webpack-simple 中的 axios 从 url 接收一个 json 文件
【发布时间】:2019-08-21 04:50:48
【问题描述】:

我是 vue.js 的新手,我尝试从 url 接收列表。 这里有一些问题:
1.我无法在main.js中定义axios,所以我可以在index.html中使用(这个解决方案对我不起作用https://stackoverflow.com/a/51374448/9582441
2.使用console.log(response)时,response为空,所以请求还没有完成

我已经安装了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

【问题讨论】:

    标签: json vue.js axios vue-cli


    【解决方案1】:

    解决方案是使用

    this.axios
    

    【讨论】:

      猜你喜欢
      • 2014-04-23
      • 1970-01-01
      • 2021-08-10
      • 2014-10-12
      • 2016-06-16
      • 1970-01-01
      • 2019-03-04
      • 2022-01-08
      • 2019-12-30
      相关资源
      最近更新 更多