Buefy: Call loading component from vuex/vuerouter

Created on 2 Nov 2019  路  3Comments  路  Source: buefy/buefy

Description

Like dialog component, the loading component should be callable from inside of a Vuex store or from VueRouter instance or event from outside.

Why Buefy need this feature

So we can attach loading state to all API call like this:

import axios from 'axios'
import loading from 'buefy'

const instance = axios.create({
    // baseURL: '/api'
  })

const loading = buefy.loading

instance.interceptors.request.use(config => {
    loading.open()
    return config
})

  instance.interceptors.response.use(response => {
    loading.close()
    return response
})

export default instance

Most helpful comment

Open method returns an instance of loading component, you have to use it to call close method. For example const myloading = Loading.open() and then myloading.close()

All 3 comments

Try import { LoadingProgrammatic as Loading } and then Loading.open()

Thanks for your quick answer but... How am I supposed to close it? Uncaught (in promise) TypeError: buefy__WEBPACK_IMPORTED_MODULE_1__.LoadingProgrammatic.close is not a function at eval

import axios from 'axios'
import { LoadingProgrammatic as loading} from 'buefy'

const instance = axios.create({
    baseURL: '/api'
})


instance.interceptors.request.use(config => {
    loading.open()
    return config
})

  instance.interceptors.response.use(response => {
    loading.close()
    return response
})

export default instance

Open method returns an instance of loading component, you have to use it to call close method. For example const myloading = Loading.open() and then myloading.close()

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ravenvn picture ravenvn  路  3Comments

kaeltis picture kaeltis  路  3Comments

keligijus picture keligijus  路  3Comments

Trevald picture Trevald  路  3Comments

daltonrooney picture daltonrooney  路  3Comments