Express project, how to make each page need to call the api extracted to form a common module to reference?

is like this, every page needs to call some api,. If you write request, on each page, it will feel cumbersome. Is there a good way to write it as a common module, and then introduce a module?


export default axios.get('/commonApi').then(data => {
    return data.data
})
import commonApi from './commonApi'

...

mounted() {
    commonApi.then(data => console.log(data))
}
Menu