我是Vuex商店的新手,由vue.js提供服务。我想在下面的场景中使用它。
1. STATE是指服务器提供的任何静态或动态数据。或者说存储在json中的数据?
<!-- title start -->
<div class="_Handler-0-1">
<x-x :path="store.glyph.path['0']":classs="store.static.class['0']"/>
</div>
<!-- title end -->
store: {
glyph: {
path: {
0: '<svg>.....</svg'>
}
},
static: {
class: {
0: 'icon-phone'
}
}
}
答案 0 :(得分:1)
值得阅读有关vuex的文档。
https://vuex.vuejs.org/en/intro.html
一切都与国家管理有关。如果需要,您可以从服务器检索数据并将其存储在那里,或者您可以存储用户输入的数据。它非常灵活,但其设计方式是确保始终正确管理
答案 1 :(得分:1)
Vuex'具有功能性生命周期:
调度程序
操作
的突变
吸气剂
调度员.dispatch
操作
动作commit
突变
突变mutate (change)
州
Getters return
部分州。
我不知道您如何完成商店的完整设置,但要检索您所在州的两个部分,我会写一个返回两个部分的吸气剂。
const store = new Vuex.Store({
state: {
glyph: {
path: '<svg>.....</svg>'
},
static: {
class: 'icon-phone'
}
},
getters: {
glyph: state => state.glyph,
static: state => state.static
}
})
<template>
<div class="_Handler-0-1">
<x-x :path="glyph.path":class="static.path"/>
</div>
</template>
<script>
import { ...mapGetters } from 'vuex'
export default {
name: 'foo',
computed: {
...mapGetters(['glyph', 'static'])
}
}
</script>
另外值得一提的是,静态是一个保留字。