Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

152
Views
Vue3 v-model remove spaces on input paste

Consider the following example Vue component:

Template:

<template>
  <input
    id="pin"
    v-model="pin"
    type="password"
    name="pin"
    placeholder="Pin"
    @input="removeSpace($event.target)"
  />
</template>

Script:

<script>
import { ref } from 'vue'

const pin = ref('')

const removeSpace = (target) => {
  pin.value = target.value.replace(/\s/g, '')
}
</script>

How would I go about moving the removeSpace function in this component to VueX4 store? So I can use it in multiple components? Can't seem to get it to work, the input field doesn't update.

I have tried something as follows:

Template:

<template>
  <input
    id="test"
    v-model="store.state.testPin"
    type="text"
    name="test"
    placeholder="test"
    @input="store.dispatch('removeSpace', $event.target)"
  />
</template>

VueX store:

import { createStore } from 'vuex'

const store = createStore({
  state: {
    testPin: ''
  },
  actions: {
    removeSpace(state, target) {
      state.testPin = target.value.replace(/\s/g, '')
    }
  }
})

export default store
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!