Skip to content

How to change parent value from child #377

Closed Answered by logistor
lioutall asked this question in Q&A
Discussion options

You must be logged in to vote

When parent object is constructed this.abc points both parent abc and child abc. But when callme get invoked in child object this is bound to child abc.

You can avoid problem with this using arrow function. Parent also needs an update.

<div @name="parent">  
  <child :clickDo="callme" />
  <div>parent {abc}</div>

  <script>
    constructor() {
      this.abc = 'AAA'
    }
    callme = (msg) => {
      this.abc = msg
      this.update()
    }
  </script>
</div>

<button @name="child" @click="click">
  child {abc}
  <script>
    constructor({ clickDo }) {
      this.cb = clickDo
    }
    click() {
      this.abc = 'changed'
      this.cb('changed')
    }
  </script>
</button>


Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by lioutall
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants