0

In this SO post, shows how to add a simple config to a Vue app,

Link to SO post

The top answer uses the following JS code.

    fetch(process.env.BASE_URL + "config.json")
  .then((json) => {
    json().then((config) => {
       Vue.prototype.$config = config
       new Vue({
         router,
         store,
         render: (h) => h(App)
       }).$mount("#app")
    })
})

which I put in my TS code, and get the following error.

ERROR in D:/TFS/StudentPortal4Vue/clientapp/src/main.ts(44,13): 44:13 This expression is not callable. Type 'Response' has no call signatures. 42 | .then((json) => 43 | {

44 | json().then((config) => | ^ 45 | { 46 | Vue.prototype.$config = config; 47 | new Vue({ Version: typescript 4.3.2

It's obvious to me that I have a type problem, but I'm stumped as to how to fix it.

(Super new at ts, and old but noobish at JS & Vue)

Eric Brown - Cal
  • 14,135
  • 12
  • 58
  • 97

1 Answers1

2

There is an error in the code ...should look like this:

fetch(process.env.BASE_URL + "config.json")
.then((response) => response.json())
.then((config) => {
       Vue.prototype.$config = config
       new Vue({
         router,
         store,
         render: (h) => h(App)
       }).$mount("#app")
})
Michal Levý
  • 33,064
  • 4
  • 68
  • 86
  • That looks like it worked, how do it use it in a situation like this: Vue.use( Auth, { issuer: this.$config.okta_issuer, client_id: 'XXXXXXXXXXXXXXXXXX', redirect_uri: 'http://localhost:8080/callback', scopes: [ 'openid', 'profile', 'email' ], tokenManager: { storage: 'sessionStorage' }, } ); – Eric Brown - Cal Aug 13 '21 at 18:31