A
A
Artem Nanavov2020-01-13 19:26:59
Vue.js
Artem Nanavov, 2020-01-13 19:26:59

Axios connection: "close"?

I give an axios request to get data from api, and according to the instructions for api, the connection should be equal to keep-alive, but I have close, and I want to change close to keep-alive, but I don’t know how,
here is the request code

import router from '../../router/index'
import axios from 'axios'

export default{
    state: { 
        posts: [],
        perPage: 15,
        page: 1,
        total: 0,
        loading: false,
        s: []
    },
    
    getters: {
        numPages: state => Math.ceil( state.total / state.perPage ),
    },
    
    mutations: {
        updateLoading: ( state, loading ) => state.loading = loading,
        updatePosts: ( state, { posts, total, page } ) => Object.assign( state, { posts, total, page } ),
    },
    
    actions: {
        async fetchPosts( { commit, state }, page ) {
            commit('updateLoading', true)
    
            const params = router.currentRoute

            const start = ( page - 1 ) * state.perPage;

            const url = `/api/photos?${ params.name }=true&start=${ start }&limit=15`
            
            try {
                const response = await axios.get( url, { proxyHeaders: false,
                    credentials: false, } )

                console.log( response )

                const posts = await response.data

                console.log( posts )

                const total = posts.totalItems
                
                commit( 'updatePosts', { posts, total, page }) 
            } catch (e) {
                console.error(e)
            }
    
            commit( 'updateLoading', false )
        },
    }
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question