Skip to content

Commit 8d0a095

Browse files
committed
fix changing global config by component
1 parent 7201d3f commit 8d0a095

File tree

4 files changed

+13
-3
lines changed

4 files changed

+13
-3
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[![npm Version](https://badgen.net/npm/v/@coders-tm/vue-number-format?color=green)](https://www.npmjs.com/package/@coders-tm/vue-number-format)
22
[![npm Downloads](https://badgen.net/npm/dt/@coders-tm/vue-number-format?color=green)](https://www.npmjs.com/package/@coders-tm/vue-number-format)
3-
[![github Stars](https://badgen.net/github/stars/coders-tm/vue-number-format?color=green)](https://www.npmjs.com/package/@coders-tm/vue-number-format)
3+
[![github Stars](https://badgen.net/github/stars/coders-tm/vue-number-format?color=green)](https://github.com/coders-tm/vue-number-format)
44
[![Bundlephobia](https://badgen.net/bundlephobia/minzip/@coders-tm/vue-number-format?color=green)](https://bundlephobia.com/result?p=@coders-tm/vue-number-format)
55
[![License](https://badgen.net/github/license/coders-tm/vue-number-format?color=green)](https://github.com/coders-tm/vue-number-format/blob/master/LICENSE)
66

src/component.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212

1313
<script>
1414
import directive from './directive'
15-
import options from './options'
15+
import { cloneDeep } from './core'
16+
import defaultOptions from './options'
17+
18+
const options = cloneDeep(defaultOptions)
1619
1720
export default {
1821
name: 'Number',

src/core.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@ import NumberFormat from './number-format'
22

33
export const CONFIG_KEY = '__input-facade__'
44

5+
/**
6+
* Creates a fuction to clone the objcet
7+
*/
8+
export function cloneDeep(data) {
9+
return JSON.parse(JSON.stringify(data))
10+
}
11+
512
/**
613
* Creates a CustomEvent('input') with detail = { facade: true }
714
* used as a way to identify our own input event

src/directive.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const CONFIG_KEY = core.CONFIG_KEY
77
export default {
88
beforeMount: (el, { value, modifiers }, vnode) => {
99
el = core.getInputElement(el)
10-
const config = Object.assign({}, defaults, value, modifiers)
10+
const config = Object.assign({}, core.cloneDeep(defaults), value, modifiers)
1111
el[CONFIG_KEY] = { config }
1212
// set initial value
1313
core.updateValue(el, vnode, { force: config.prefill, clean: true })

0 commit comments

Comments
 (0)