vue.js - 如何调试 Vue.js 组件中的 mapGetter 属性?
问题描述
我是 Vue.js 的新手。我最近学习了 Vuex 并尝试在我的项目中实现。dashboard
我正在从我的组件调用一个动作调度。message
并在组件计算部分调用 ...mapGetter 。我想调试我得到的数据。
我已经搜索了我的问题。但是找不到。我了解到我不能在计算中使用 console.log()。我必须使用调试器。但是当我使用调试器时,它说调试器是一个保留字。
在我的商店:
state: {
conversationThreads: [],
conversation: [],
users: [],
},
getters: {
conversation: state => {
return state.conversation;
}
},
mutations: {
[MUTATION_TYPES.SET_CONVERSATION](state, conversationThread){
state.conversation= conversationThread;
}
},
actions: {
getConversationByID: ({ commit }, conversationInfo) => {
console.log("conversationData: ", conversationInfo)
axios.get("https://some_API" + conversationInfo.id)
.then(response => {
let conversationThread = response.data.messages.data.map(res => ({
name: res.from.name,
msg: res.message
}));
commit(MUTATION_TYPES.SET_CONVERSATION, conversationThread);
})
.catch(error => console.log(error))
}
}
在我的仪表板组件中:
methods: {
selectedDiv: function(conversationInfo, event){
this.$store.dispatch('getConversationByID', conversationInfo)
}
}
在我的消息组件中:
computed: {
...mapGetters([
"conversation"
]),
debugger
},
解决方案
您可以在不使用的情况下获得类似的功能mapGetter
,下面是示例。
computed: {
yourProperty(){
const profile = this.$store.getters.profile;
console.log('profile: ', profile); //Debug
return profile;
}
},
另一种选择是监视计算属性。
computed: {
...mapGetters(["profile"]),
},
watch: {
profile: {
handler(profile) {
console.log('profile: ', profile); //Debug
},
deep: true
}
},
这里 deep true 选项用于监视profile
对象的关键更新。如果没有提供 deep true ,那么只有当profile
getter 被新对象重新分配时才会调用 watch。
推荐阅读
- ios - 激活 ReightViewMode 时,SearchBar 会自动将未创建的 ImageView 添加到后台
- python - 得到 AttributeError: 'FarmerClass' object has no attribute 'farmer_name' 在以下代码中
- python - 编码二次公式时的ValueError
- c++ - 如何将函数模板作为模板参数传递?
- forecasting - 比较不同波动率市场的 MAPE
- sql - Docker-compose 与 H2 docker 数据库的 setup.sql 文件
- css - 用于交互式水平滚动网站的最佳软件是什么?
- basic - 如何在 BASIC V2 中“操作”字符串?
- r - R - 从数据帧中提取时间独立的事件
- javascript - 从ajax调用的结果向传单地图添加标记-未捕获的TypeError:无法读取null的属性'lat'