[英]vuex action api call does not update dom
I'm using vuex Actions to call api for getting data. 我正在使用vuex Actions调用api来获取数据。 On the network tab, I can see data that loads successfully, but it doesn't display every time.
在网络选项卡上,我可以看到成功加载的数据,但不会每次都显示。 I have to reload the page repeatedly to display it.
我必须重复重新加载页面才能显示它。
what is the solution? 解决办法是什么?
Footer.vue Footer.vue
...mapGetters([
'getInfo',
'getSocials'
])
and template: 和模板:
<li><i class="fas fa-phone"></i> تلفن تماس: <a :href="`tel:${getInfo.number}`">{{ getInfo.number
}}</a></li>
<li><i class="fas fa-envelope"></i> ایمیل: <a :href="`mailto:${getInfo.email}`" class="roboto">{{
getInfo.email }}</a></li>
<li><i class="fab fa-telegram-plane"></i> تلگرام: <a :href="getSocials[1]"
class="roboto">@telegram</a></li>
<li><i class="fab fa-twitter"></i> توییتر: <a :href="getSocials[3]" class="roboto">@twitter</a>
</li>
<li><i class="fab fa-instagram"></i> اینستاگرام: <a :href="getSocials[0]"
class="roboto">@instagram</a></li>
<li><i class="fab fa-linkedin-in"></i> لینکدین: <a :href="getSocials[2]"
class="roboto">@linkedin</a></li>
and this is vuex: 这是vuex:
state: {
socials: [],
info: {}
},
mutations: {
SET_SOCIALS(state, val) {
state.socials.push(val)
},
SET_INFO(state, val) {
state.info.title = val.title
state.info.number = val.number
state.info.about = val.about_me
state.info.email = val.mail
}
},
actions: {
setSocials({commit}) {
Http.get("/config")
.then(response => {
let social = response.data.socialmedia;
for (const [key, value] of Object.entries(social)) {
commit('SET_SOCIALS', `https://${value}`)
}
})
},
setInfo({commit}) {
Http.get("/config")
.then(response => {
let res = response.data.site.info;
commit('SET_INFO', res)
})
}
},
getters: {
getSocials: state => state.socials,
getInfo: state => state.info
}
and i dispatched actions in Main component called App.vue in created hook. 我在创建的钩子中调用了名为App.vue的主要组件中的操作。
this.$store.dispatch('setSocials');
this.$store.dispatch('setInfo');
Please let me know the solution? 请让我知道解决方案?
Thanks. 谢谢。 http://uupload.ir/files/6k5d_ezgif-4-6c8b9e45ac01.gif
http://uupload.ir/files/6k5d_ezgif-4-6c8b9e45ac01.gif
update: 更新:
i found that dom is not updating when api calls. 我发现当api调用时dom没有更新。
there is no problem with data and indexes. 数据和索引没有问题。
when i click on the searchBox and searchbox
data will be true, dom will update. 当我点击searchBox并且
searchbox
数据为真时,dom会更新。
i don't know why is this happen? 我不知道为什么会这样?
How the socials's length is existed ? 社交的长度是如何存在的? when component created.
何时创建组件。 So the index of socials maybe out of range.
所以社交指数可能超出范围。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.