Skip to content

Commit

Permalink
fix: deepmerge functoin object type --build
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronlamz committed May 6, 2022
1 parent fafb073 commit ac5f6bb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
20 changes: 19 additions & 1 deletion examples/vite-project/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<h2>Current Lang from $i18n.currentLocale: {{ currentLocale }}</h2>
<h2>Test Cases:</h2>
<p>Key[button.add: {{ $t('button.add') }}</p>
<p>Key[params]: {{ $t('params', 'function value') }}</p>
<p>Key[params]: {{ $t('params', param) }}</p>
<p>Key Array: {{ $t(['简体', '繁体', '英文']) }}</p>
<p>Key [global option]: {{ $t('global') }}</p>
<p>
Expand All @@ -29,6 +29,19 @@
Change Lang to en by $i18n.changeLocale
</button>
</p>
<p>
<button @click="changeFunctionParams('zhCHS')">
Change param to zhCHS
</button>
</p>
<p>
<button @click="changeFunctionParams('zhCHT')">
Change param to zhCHT
</button>
</p>
<p>
<button @click="changeFunctionParams('en')">Change param to en</button>
</p>
</template>
<script lang="ts">
import { useI18n } from '../../../src/index'
Expand Down Expand Up @@ -58,9 +71,13 @@ export default {
methods: {
changLang(locale: string) {
;(this as any).$i18n.changeLocale(locale)
},
changeFunctionParams(param: string) {
;(this as any).param = param
}
},
setup() {
let param = ref('zhCHS')
const i18n = useI18n()
const { changeLocale, currentLocale } = i18n
const swtchLang = (locale: string) => {
Expand All @@ -69,6 +86,7 @@ export default {
console.log(fromMapTips)
let tips = ref(fromMapTips)
return {
param,
currentLocale,
tips,
swtchLang
Expand Down
3 changes: 2 additions & 1 deletion src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ export function mergeDeep(
source: Record<string, any>
): Record<string, any> {
Object.keys(source).forEach(key => {
if (source[key] instanceof Object && key in target) {
// merging the same key on both objects
if (typeof source[key] === 'object' && source[key] instanceof Object && key in target) {
source[key] = {
...source[key],
...mergeDeep(target[key], source[key])
Expand Down

0 comments on commit ac5f6bb

Please sign in to comment.