用ts写vue 子组件怎么发射两个事件出来?

点击按钮的时候发送两个事件
this.$emit('aa', 11)
this.$emit('bb', 22)

<template>
  <div>
    <button @click="btnClick(index, item)" v-for="(item, index) in option" :key="item.value" :class="[{'active':activeValue===item.value}, 'btn']">{{item.label}}</button>
  </div>
</template>

<script lang="ts">
import { Component, Model, Emit, Prop, Vue, Ref, Watch, Provide } from "vue-property-decorator";

@Component({
  components: {}
})
export default class extends Vue {
  @Model('click') activeValue: any
  @Prop({ default: () => [] }) option: any

  act = this.activeValue

  @Emit('click')
  btnClick(index, item) {
    this.activeValue = item.value
    return this.activeValue
  }



  mounted() {}
}
</script>
阅读 5.7k
2 个回答

一楼的方法 还是不能返回多个值
换个思路吧, 点击的时候触发一个函数, 这个函数触发两个@emit事件函数

  @Emit('click1')
  @Emit('click2')
  btnClick(index, item) {
    this.activeValue = item.value
    return this.activeValue
  }
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题