美文网首页
vue父-子-点击事件传递

vue父-子-点击事件传递

作者: O蚂蚁O | 来源:发表于2020-04-11 11:10 被阅读0次

1、

$emit

2、
父组件

<template>
  <section class="product-entering-list">
    <child
      :options="options"
    ></child>
  </section>
</template>

<script>
import child from "./child"
export default {
  name: 'test',
  components: { child },
  data() {
    return {
      options: [
        {
          txt: '点击我',
          handler: () => {
            this.handleClick()
          }
        }
      ]
    }
  },
  mounted() {
    
  },
  methods: {
    handleClick() {
      console.log('我是父组件');
    }
  }
}
</script>

<style lang="less">

</style>

子组件

<!--
 * @Author: your name
 * @Date: 2020-04-11 10:37:24
 * @LastEditTime: 2020-04-11 10:57:50
 * @LastEditors: your name
 * @Description: In User Settings Edit
 * @FilePath: \longzhu-mdm-web\src\views\kit\productLibrary\productScan\child.vue
 -->
<template>
  <section class="product-entering-list">
    <el-button v-for="(item, index) in options" :key="index" 
      type="primary"
      @click.stop="() => item.handler()"
    >
      {{item.txt}}
    </el-button>
  </section>
</template>

<script>

export default {
  name: 'child',
  components: { },
  props: {
    options: { 
      type: Array,
      default: () => ([])
    },
  },
  data() {
    return {
    }
  },
  mounted() {
    
  },
  methods: {
    handleClick(val) {
      
    }
  }
}
</script>

<style lang="less">

</style>

相关文章

  • vue父-子-点击事件传递

    1、 2、父组件 子组件

  • Vue父组件调用子组件事件

    Vue父组件向子组件传递事件/调用事件 不是传递数据(props)哦,适用于 Vue 2.0 方法一:子组件监听父...

  • vue常见面试题

    1.vue优点 2.vue父组件向子组件传递数据? 3.子组件像父组件传递事件 4.v-show和v-...

  • Vue-自定义事件

    在父组件使用prop 传递数据给子组件,子组件则是通过事件传递数据给父组件的。 Vue实例都会实现事件接口: 1....

  • React Native 函数回调

    子组件传递事件到父组件 碰到一个需求是:在子组件中点击按钮,需要将点击事件传递到父组件中,这个需求在iOS中可以很...

  • vue学习

    vue中的事件传递 父子组件传值通过props传递,父组件 :name=“name(父数据)”子组件 props内...

  • vue组件嵌套(模态框)

    在vue中父组件向自子组件传递props; 子组件向父组件传递属性是用$emit(发布订阅); 实例基本逻辑:点击...

  • 父传子和子传父

    父传子 这里我们父组件向子组件 传递this.state.isEdit的变量 子传父 点击事件()=>{this...

  • 【Vue学习笔记】—— 组件之间传递数据 { }

    学习笔记 作者:oMing Vue 组件1.通过绑定传递数据(父组件 ——》 子组件) 2.通过事件传递数据 ...

  • 微信小程序父子组件传值

    子传父:事件传递 父传子:属性传递

网友评论

      本文标题:vue父-子-点击事件传递

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