无法使用 axios 从服务器获取数据获取响应

时间:2021-05-18 20:09:52

标签: vue.js http axios get response

我正在尝试使用 axios get 响应从服务器获取 json 数据。

<script>
  import axios from 'axios';

  export default {
    data() {
      return {
        films: [],
      };
    },
    methods: {
      getFilms() {
        const path = 'http://localhost:5000/api/v1.0/films';
        axios.get(path)
          .then((res) => {
            this.films = res.data.films;
          })
          .catch((error) => {
            console.error(error);
          });
      },
    },
    created() {
      this.getFilms();
    },
  };
</script>

但结果我有空列表。我怎样才能解决这个问题?或者 mb 还有另一种从服务器获取数据的方法。

0 个答案:

没有答案