Within my store.js
file, I have a state called user_data
, with its initial method set to fetch_user_data
:
export default new Vuex.Store({
state: {
user_data: util.fetch_user_data('username')
...
}
located in the util.js
file:
util.fetch_user_data = function(username){
Lml_http('get', Api_urls.productconfig_common.user_data(username), null, response => {
return response.data // data is obtained here, as shown in the debugger.
}, error => {
})
}
However, when attempting to use the user_data
from the state
, it returns as undefined
.
EDIT-1
I aim to utilize the fetch_util
method in the store.js
file for data retrieval and commit to the state
.
EDIT-2
The code snippet for the lml_http
function is provided below:
var lml_http = function (method, url, params, success_cb, error_cb, multipart_formdata=undefined) {
var format_to_form_data = function(data){
let formData = new FormData()
for (let item in data) {
formData.append(item, data[item])
}
return formData
}
var lowercase_method = method.toLowerCase()
var formated_params = params
var header_config = null
if (multipart_formdata) {
header_config = {
headers: {
'Content-Type': 'multipart/form-data'
}
}
formated_params = format_to_form_data(formated_params)
}
if(lowercase_method === "get") {
formated_params = {params: formated_params}
if (!header_config) {
Axios.get(url, formated_params).then(response => {
success_cb(response)
return
}).catch(response => {
error_cb(response)
return
})
} else {
Axios.get(url, format_to_form_data(formated_params), header_config).then(response => {
success_cb(response)
return
}).catch(response => {
error_cb(response)
return
})
}
return
}
else {
if(!header_config) {
Axios[method](url, formated_params).then(response => {
success_cb(response)
}).catch(response => {
error_cb(response)
})
return
}else {
Axios[method](url, formated_params, header_config).then(response => {
success_cb(response)
}).catch( response => {
error_cb(response)
})
return
}
}
}