首页 > 解决方案 > Vue.Js axios 获取请求未通过

问题描述

我正在尝试使用来自 vuex store.js 文件的 axios 发送获取请求, 当我在浏览器中搜索 api 时,我使用的 api 是https://openlibrary.org/dev/docs/api/search工作得很好,但是,当我使用我正在处理的应用程序使用 axios 发送请求时,它什么也没做。

这是store.js代码

import Vue from 'vue'
import Vuex from 'vuex'
import axios from 'axios'

Vue.use(Vuex)

export default new Vuex.Store({
    state: {},
    mutations: {},
    actions: {
        findBook({commit,  dispatch}, book) {
            console.log('logged before the request'); //this gets logged to the console

            axios.get('http://openlibrary.org/search.json?title=the+lord+of+the+rings')
                .then(res => {
                    console.log(`logged after the request`); //this doesn't get logged 
                    console.log(res);
                }).catch(err => console.log(err))
        }
    }
})

此外,我从 catch 块中完全没有错误,

有人能告诉我我在这里想念什么吗?提前致谢。

标签: javascriptvue.jsaxiosvuex

解决方案


推荐阅读