Answer the question
In order to leave comments, you need to log in
How to pass variable value from state to Vue component variable?
Hello. There is a Users component:
export default {
name: 'Users',
data: () => ({
showMoreBtn: false
}),
async mounted () {
this.showMoreBtn = this.$store.state.showMore
console.log(this.$store.state.showMore)
}
}
export default {
state: {
userList: [],
nextUrl: null,
showMore: false
},
mutations: {
createUserList (state, users) {
state.nextUrl = users.links.next_url
if (state.nextUrl !== null) {
state.showMore = true
} else {
state.showMore = false
}
console.log(state.showMore)
}
},
actions: {
async fetchUsers ({ commit }) {
const userList = await fetch('httsp://some-url').then(response => response.json())
commit('createUserList', userList)
}
},
getters: {
getUserList: state => {
return state.userList
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question