(十四)Vuex CompositonApi

2023-02-22 19:14:32 浏览数 (1)

一、如何在 compositionApi 中获取 store
代码语言:javascript复制
<script setup>
const store = userSore()

// 模板直接使用
const users = computed( () => store.state.users)
cosnt blogs = computed( () => store.state.blogs)
</script>
二、获取 getter
代码语言:javascript复制
<script setup>
const store = userSore()

// 不带命名空间直接访问
cosnt limitUserContStr = computed( () => store.getters.limitUserContStr)

// 访问带命名空间的
const limitBlogsContStr = comuted( () => store.getters["blogs/limitBlogsContStr"])
</script>
三、使用 mutations actions
代码语言:javascript复制
<script setup>
const store = userStore()

// 触发 mutations
cosnt addUser = (payload) => store.commit('addUser', playload)

// 触发 actions
const addBlogs = (playload) => store.dispatch('addBlogs', playload)
</script>

0 人点赞