【问题标题】:pass a value of variable from child component to parent将变量的值从子组件传递给父组件
【发布时间】:2017-05-19 23:11:36
【问题描述】:

如何将 v-model 的值从另一个组件中的一个组件传递给它的父亲?我在表单组件中制作了一个小提前输入组件,现在我正试图将查询模型放到公司模型中。

<modal-client-add inline-template>
    <div class="modal-mask" id="add-client" v-if="showModal" @close="showModal = false" tabindex="-1" role="dialog">
        <div class="modal-wrapper">
            <div class="modal-container">
                <form method="POST" action="/clients" accept-charset="UTF-8" enctype="multipart/form-data" _lpchecked="1" @submit.prevent="onSubmit">
                <div class="modal-header">
                    <button type="button" class="pull-right" @click="closeModal">×</button>
                    <h4 class="modal-title">Add Client</h4>
                </div>
                <div class="modal-body">
                        <div class="row">
                            <div class="col-md-12">
                            
                            
                                <keevo-typeahead inline-template>
                                    <div class="form-group typeahead-wrapper">
                                        <label for="company"></label>
                                        <input name="company" class="form-control" autocomplete="off"
                                               v-model="query"
                                               :class="{ loading: isLoading }"
                                               @input="update" />
                                        <ul class="typeahead" v-if="show" >
                                            <li v-for="result in results" @click="select" v-html="result.name"></li>
                                        </ul>
                                    </div>
                                </keevo-typeahead>
                                
                                
                            </div>
                            
                          <div class="modal-footer">
                              <button class="btn btn-default" @click.prevent="closeModal">Close</button>
                             <button type="submit">
                             Submit
                             </button>
                          </div>
                        
                      </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</modal-client-add>

感谢您的建议!

【问题讨论】:

    标签: javascript vue.js vue-component


    【解决方案1】:
    1. 在子进程中发出事件:`this.$emit('myevent', yourVariable)
    2. 在父级中处理事件:`
    3. eventHandlerFunction 中使用您发出的数据

    【讨论】:

      猜你喜欢
      • 2020-07-23
      • 2020-02-04
      • 2020-10-17
      • 2018-05-01
      • 2020-02-02
      • 2019-02-24
      • 2019-08-25
      • 2017-11-09
      • 2019-02-17
      相关资源
      最近更新 更多