0

While using Bootstrap-Vue as UI framework, I am trying to make a custom form component and use it in several parent components. Here is my form component

<template>
  <b-form>
    <b-input-group>
      <b-form-input placeholder="Post Title"></b-form-input>
      <wysiwyg-input placeholder="Post Content" />
    </b-input-group>
  </b-form>
</template>

and the parent component is

<FormFields :title="title" :content="content" />

How can i access the value in parent component from child component.

Note: I am using vue-quill editor as well.

Here is the codesandbox link: https://codesandbox.io/s/mystifying-benz-w8wgu?file=/src/App.vue

Thanks in advance !

1 Answer 1

0

Define a prop on your child component and pass the data to it when you use it in the parent:

// ChildComponent.vue
export default {
  props: {
    someData: {}
  }
}
// ParentComponent.vue
<template>
  <child-component :some-data="myData"></child-component>
</template>

<script>
export default {
  data() {
    return {
      myData: {...}
    }
  }
}
</script>
Sign up to request clarification or add additional context in comments.

3 Comments

this method shows the following message in console. "[Vue warn]: Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-renders. Instead, use a data or computed property based on the prop's value. Prop being mutated"
It seems like you are mutating the prop in your child component. Try avoiding that. Otherwise, you have to use .sync modifier See this: vuejs.org/v2/guide/components-custom-events.html#sync-Modifier
props should be immutable - i.e. "read-only". if you need to update the value for some reason, either create a local copy of the prop data inside your child component, or $emit the updated value back to the parent for it to update the prop.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.