• <bdo id='pZwM1'></bdo><ul id='pZwM1'></ul>

        <i id='pZwM1'><tr id='pZwM1'><dt id='pZwM1'><q id='pZwM1'><span id='pZwM1'><b id='pZwM1'><form id='pZwM1'><ins id='pZwM1'></ins><ul id='pZwM1'></ul><sub id='pZwM1'></sub></form><legend id='pZwM1'></legend><bdo id='pZwM1'><pre id='pZwM1'><center id='pZwM1'></center></pre></bdo></b><th id='pZwM1'></th></span></q></dt></tr></i><div id='pZwM1'><tfoot id='pZwM1'></tfoot><dl id='pZwM1'><fieldset id='pZwM1'></fieldset></dl></div>
      1. <small id='pZwM1'></small><noframes id='pZwM1'>

        <legend id='pZwM1'><style id='pZwM1'><dir id='pZwM1'><q id='pZwM1'></q></dir></style></legend>
      2. <tfoot id='pZwM1'></tfoot>

        如何在父事件上调用子组件的函数

        时间:2023-09-05
        <tfoot id='igXW1'></tfoot>
        • <bdo id='igXW1'></bdo><ul id='igXW1'></ul>

            <legend id='igXW1'><style id='igXW1'><dir id='igXW1'><q id='igXW1'></q></dir></style></legend>

              <i id='igXW1'><tr id='igXW1'><dt id='igXW1'><q id='igXW1'><span id='igXW1'><b id='igXW1'><form id='igXW1'><ins id='igXW1'></ins><ul id='igXW1'></ul><sub id='igXW1'></sub></form><legend id='igXW1'></legend><bdo id='igXW1'><pre id='igXW1'><center id='igXW1'></center></pre></bdo></b><th id='igXW1'></th></span></q></dt></tr></i><div id='igXW1'><tfoot id='igXW1'></tfoot><dl id='igXW1'><fieldset id='igXW1'></fieldset></dl></div>
                • <small id='igXW1'></small><noframes id='igXW1'>

                    <tbody id='igXW1'></tbody>
                  本文介绍了如何在父事件上调用子组件的函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  在 Vue 2.0 中,文档和 others 很清楚表示父母与孩子之间的交流是通过道具进行的.

                  In Vue 2.0 the documentation and others clearly indicate that communication from parent to child happens via props.

                  父母如何通过道具告诉孩子事件发生了?

                  How does a parent tell its child an event has happened via props?

                  我应该只看一个名为 event 的道具吗?这感觉不对,替代方案也不对($emit/$on 用于子级到父级,集线器模型用于远距离元素).

                  Should I just watch a prop called event? That doesn't feel right, nor do alternatives ($emit/$on is for child to parent, and a hub model is for distant elements).

                  我有一个父容器,它需要告诉其子容器可以在 API 上执行某些操作.我需要能够触发函数.

                  I have a parent container and it needs to tell its child container that it's okay to engage certain actions on an API. I need to be able to trigger functions.

                  推荐答案

                  给子组件一个ref,用$refs直接调用子组件上的方法.

                  Give the child component a ref and use $refs to call a method on the child component directly.

                  html:

                  <div id="app">
                    <child-component ref="childComponent"></child-component>
                    <button @click="click">Click</button>  
                  </div>
                  

                  javascript:

                  javascript:

                  var ChildComponent = {
                    template: '<div>{{value}}</div>',
                    data: function () {
                      return {
                        value: 0
                      };
                    },
                    methods: {
                      setValue: function(value) {
                          this.value = value;
                      }
                    }
                  }
                  
                  new Vue({
                    el: '#app',
                    components: {
                      'child-component': ChildComponent
                    },
                    methods: {
                      click: function() {
                          this.$refs.childComponent.setValue(2.0);
                      }
                    }
                  })
                  

                  有关详细信息,请参阅 关于 refs 的 Vue 文档.

                  For more info, see Vue documentation on refs.

                  这篇关于如何在父事件上调用子组件的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:捕获点击围绕 iframe 的 div 下一篇:jQuery:同一事件的多个处理程序

                  相关文章

                  最新文章

                    • <bdo id='ph5MJ'></bdo><ul id='ph5MJ'></ul>

                  1. <tfoot id='ph5MJ'></tfoot>
                    <i id='ph5MJ'><tr id='ph5MJ'><dt id='ph5MJ'><q id='ph5MJ'><span id='ph5MJ'><b id='ph5MJ'><form id='ph5MJ'><ins id='ph5MJ'></ins><ul id='ph5MJ'></ul><sub id='ph5MJ'></sub></form><legend id='ph5MJ'></legend><bdo id='ph5MJ'><pre id='ph5MJ'><center id='ph5MJ'></center></pre></bdo></b><th id='ph5MJ'></th></span></q></dt></tr></i><div id='ph5MJ'><tfoot id='ph5MJ'></tfoot><dl id='ph5MJ'><fieldset id='ph5MJ'></fieldset></dl></div>

                  2. <legend id='ph5MJ'><style id='ph5MJ'><dir id='ph5MJ'><q id='ph5MJ'></q></dir></style></legend>

                      <small id='ph5MJ'></small><noframes id='ph5MJ'>