vue3监听pinia中数据变动
cv大魔王 2022-08-09 piniavue3 分享
当我们需要时刻监听pinia中state内容变动时,例如ElementPlus框架需要监听全局国际化变动,此时应该如何操作呢?
答案是使用computed
<script setup>
import {useThemeStore} from '@/stores/theme'
import zhCn from 'element-plus/dist/locale/zh-cn.mjs'
import en from 'element-plus/dist/locale/en.mjs'
import { computed } from "vue"
const themeStore = useThemeStore()
const locale = computed(() => (themeStore.language === 'zh' ? zhCn : en))
</script>
评论区
暂无评论~~