As I navigate through the learning curve of vue.js, a seemingly simple question has arisen: how can I achieve the following task?
Within one of my vue components, I am facing challenges with the implementation of the "loadSuggestedUsers" method. Here is the code snippet:
async loadSuggestedUsers() {
if (!this.suggestionUrl) return false
else this.isSearching = true;
this.cancelPreviousRequest();
await axios.get(`/${Helper.getLocale()}/dashboard/${this.suggestionUrl}`, {
params: {
page: this.suggestedUsersData.page,
per_page: this.suggestedUsersData.perPage,
search_text: this.searchText,
nationality: this.selectedNationalities
},
cancelToken: this.requestToken.token
}).then(({data}) => {
collect(data.data).each((user) => {
if (!this.suggestedUsers.some(obj => obj.id === user.id)) {
this.suggestedUsers.push(user)
} else if (
user.project_specific_job_title_id &&
!this.suggestedUsers.some(obj => obj.project_specific_job_title_id === user.project_specific_job_title_id)
) {
this.suggestedUsers.push(user)
}
})
this.suggestedUsersData.perPage = data.per_page
this.suggestedUsersData.total = data.total
this.isSearching = false
}).catch(error => {
if (error instanceof axios.Cancel) return false;
});
}
My current endeavour involves invoking this method from the component using the store
.
Within my store, there exists a JavaScript file named TestStore.JS
.
Here are my questions:
How do I recreate the above method in my TestStore.JS and subsequently call that recreated method in my component?