Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
357 views
in Technique[技术] by (71.8m points)

vue.js - How to use custom input component in vuejs?

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 !


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...