站内搜索:
首页 >> 前端 >> 内容
Vue之组件通讯

时间:2017/4/4 9:17:00

Vue之组件通讯:1 父子组件通讯,先触发子组件的mounted钩子,再触发父组件的mounted钩子。


1.1 子组件向父组件传递数据

子组件中调用this.$emit([自定义事件:string],[传出数据])。 父组件使用v-on监听自定义事件,子组件触发this.$emit时会自动触发。

参考代码:

//parent component

//child component
//...
    this.$emit('childready',this);
//...

  • 上一篇:浅谈node.js和npm
  • 下一篇:JS排序算法
  • 返回顶部