美文网首页
vue 子组件触发父组件的方法

vue 子组件触发父组件的方法

作者: 卡戎li | 来源:发表于2018-10-06 09:12 被阅读0次

方法一

  • 子组件
<template>
    <button @click="submit">提交</button>
</template>
<script>
export default {
  methods: {
    submit: function () {
      // 子组件中触发父组件方法ee并传值cc12345
      this.$emit('ee', 'cc12345')
    }
  }
}
</script>
  • 父组件
<template>
    <button @click="submit">提交</button>
</template>
<script>
export default {
  methods: {
    submit: function () {
      // 子组件中触发父组件方法ee并传值cc12345
      this.$emit('ee', 'cc12345')
    }
  }
}
</script>

方法二

  • 子组件
<template>
    <button @click="submit">提交</button>
</template>
<script>
export default {
  methods: {
    submit: function () {
      // 子组件中触发父组件方法ee并传值cc12345
      this.$emit('ee', 'cc12345')
    }
  }
}
</script>
  • 父组件
<template>
    <editor id="editor" class="editor" :onsubmit="cc"></editor>
</template>
<script>
export default {
  methods: {
    cc: function (str) {
      alert(str)
    }
  }
}
</script>

相关文章

网友评论

      本文标题:vue 子组件触发父组件的方法

      本文链接:https://www.haomeiwen.com/subject/lhgcaftx.html