Search code examples
vue.jsvuejs2vue-componentvuex

Vue JS: Save the value of a prop in a component


How do I save the value of a dynamic prop? The values of the prop change dynamically, but I want to work with the first value the component receives by the prop. So it's basically like the prop was only send once to the component. How do I achieve this and how is it done in Vuex?


Solution

  • I don't think you need to use Vuex for this. Inside your component, you could have a variable that receives the prop value on create.

    export default {
      props: ['propCount'],
      data() {
        compCount: 0
      },
      created() {
        this.compCount = this.propCount
      }
    }