Skip to content

当我们需要时刻监听pinia中state内容变动时,例如ElementPlus框架需要监听全局国际化变动,此时应该如何操作呢?

TIP

答案是使用computed

vue
<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>