Extraneous non-emits event listeners (formChange).....declare it using the “emits“ option警告出现原因及解决办法

一. 场景

vue3.0中子组件向父组件传递自定义事件时控制台报出警告如下:

在这里插入图片描述
意思是formChange、custom、downloadForm、edit、choiceAccountNum、clearData这几个自定义事件已经传递给父组件,但是无法自动继承,因为传递事件的子组件没有根节点,他在父组件中渲染为代码片段。

二. 分析

我在vue3.0中子组件向父组件传递自定义事件时,一直都是如下面这样写

export default {
  setup(props, {emit}) {
    emit('getData')
    emit('stopChange')
    ..
  }
}

父组件能拿到事件,并且控制台也不会报出警告。

但是今天却报出了上面的警告信息,根据警告信息提示,需要在子组件中通过emits注册自定义事件,于是我修改代码如下:

export default {
  emits: ['edit', 'custom', 'downloadForm', 'formChange', 'choiceAccountNum', 'clearData'],
  setup(props, {emit}) {
    emit('edit')
    emit('custom')
    emit('downloadForm')
    emit('formChange')
    emit('choiceAccountNum')
    emit('clearData')
    ..
  }
}

修改代码后,问题解决了,控制台确实不报上面的警告了。

但是,但是今天控制台为什么会报出警告呢?警告中说明的原因是传递事件的子组件没有根节点,他在父组件中渲染为代码片段。

于是我仔细检查了子组件的代码,好家伙,发现问题了
在这里插入图片描述
如上图,我确实没有根标签了,template标签中是 diva-model 两个并列的标签。
在这里插入图片描述
在这里插入图片描述
如上图,我将结构修改了,并且把emits注册自定义事件也注销了。问题得到了解决,控制台不再报出警告。

三. 总结

vue3.0 中子组件向父组件传递自定义事件时:

① 若子组件中拥有根标签,则不需要通过emits属性声明自定义事件

<template>
  <div class="根标签">
    ....
  </div>
</template>

export default {
  setup(props, {emit}) {
    emit('getData')
    emit('stopChange')
    ..
  }
}

② 若子组件中没有根标签,则需要通过emits属性来声明自定义事件

<template>
  <div class="并列标签1">
    ....
  </div>
  <div class="并列标签2">
    ....
  </div>
</template>

export default {
  emits: ['getData', 'stopChange'],
  setup(props, {emit}) {
    emit('getData')
    emit('stopChange')
    ..
  }
}

(完)

  • 4
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
Preface Organization of the Book Chapter 1 introduces the two main points to be made. Chapter 2 shows that a wide variety of seemingly different problems in a number of fields can be viewed as problems of program induction. No prior knowledge of conventional genetic algorithms is assumed. Accordingly, chapter 3 describes the conventional genetic algorithm and introduces certain terms common to the conventional genetic algorithm and genetic programming. The reader who is already familiar with genetic algorithms may wish to skip this chapter. Chapter 4 discusses the representation problem for the conventional genetic algorithm operating on fixed-length character strings and variations of the conventional genetic algorithm dealing with structures more complex and flexible than fixed-length character strings. This book assumes no prior knowledge of the LISP programming language. Accordingly, section 4.2 describes LISP. Section 4.3 outlines the reasons behind the choice of LISP for the work described herein. Chapter 5 provides an informal overview of the genetic programming paradigm, and chapter 6 provides a detailed description of the techniques of genetic programming. Some readers may prefer to rely on chapter 5 and to defer reading the detailed discussion in chapter 6 until they have read chapter 7 and the later chapters that contain examples. Chapter 7 provides a detailed description of how to apply genetic programming to four introductory examples. This chapter lays the groundwork for all the problems to be described later in the book. Chapter 8 discusses the amount of computer processing required by the genetic programming paradigm to solve certain problems. Chapter 9 shows that the results obtained from genetic programming are not the fruits of random search. Chapters 10 through 21 illustrate how to use genetic programming to solve a wide variety of problems from a wide variety of fields. These chapters are divided as follows: • symbolic regression; erro

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值