javascript - vuejs 2.0 中的递归组件通信

标签 javascript recursion vue.js vuejs2

假设组件名称是“customComponent”

及其用法示例:

<custom-component class='parent'>
  <div v-if='someTruthyCondition'>
    <custom-component class='child'></custom-component>
  </div>
</custom-component>

假设“someTruthyCondition”为真,生成 3 个组件并停止递归。

我想知道如何在vue js中子customComponent与父customComponent之间进行通信?

最佳答案

You can use functions as props in Vue.js. It’s not a common pattern because, unlike with React, Vue.js has custom events for child-to-parent communication. But for cases like this one it really comes in handy.

Unlike emitting events at each level, this is much simpler and performant since we only need to pass down the same reference to the function.

检查 this出。

关于javascript - vuejs 2.0 中的递归组件通信,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47012103/

相关文章:

c# - 尝试将递归 JavaScript 方法移植到 C#,这种方法有意义吗?

javascript - 尝试将查询绑定(bind)到 Vue.js 中 api 的每个请求的 json 字符串

javascript - s3 javascript 创建存储桶

c# - 斐波那契递归解释

javascript - (更改)angular2 中的事件 Hook

c - 递归函数输出不正确以计算数字的数字总和

javascript - 清除vuejs表单中的输入

javascript - 虚线多边形谷歌地图

javascript - 在 setTimeout 间隔期间单击另一个按钮时出现错误

javascript - 获取一个数组以两行打印,但它只打印一行