Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eslint vue/no-mutations-props #46

Open
PierreFichet opened this issue Aug 24, 2021 · 0 comments
Open

Eslint vue/no-mutations-props #46

PierreFichet opened this issue Aug 24, 2021 · 0 comments

Comments

@PierreFichet
Copy link

PierreFichet commented Aug 24, 2021

Hi all,

I ran into some issues with the eslint vue rules, particularly vue/no-mutations-props:

Mutating a prop locally is now considered an anti-pattern, e.g. declaring a prop and then setting this.myProp = 'someOtherValue' in the component. Due to the new rendering mechanism, whenever the parent component re-renders, the child component’s local changes will be overwritten.

The issue are in clickKey and setFocusToInput methods:
this.input.value = text (line 266)
this.input.selectionStart = caret.start (286)
this.input.selectionEnd = caret.end (line 287)

The workaround I made is the following:

I created an event listener on the parent component:

<vue-touch-keyboard  <props> v-on:update-form="keyboardUpdate" />

---- in component methods
    keyboardUpdate (d) {
      this.keyboard.input[d.key] = d.value
    }

In keyboard.vue, I replaced the above mentioned lines by:
this.input.value = text => this.$emit('update-form', { key: 'value', value: text })

this.input.selectionStart = caret.start => this.$emit('update-form', { key: 'selectionStart', value: caret.start })

this.input.selectionEnd = caret.end => this.$emit('update-form', { key: 'selectionEnd', value: caret.end })

Hope it serves other people!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant