Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
495 views
in Technique[技术] by (71.8m points)

javascript - VUE:当发出事件调用父组件时,我们可以获取包含发出事件传递的所有参数的参数(VUE: when emitted event call parent conponent, we can get arguments which inculdes all the parameter that emitted event pass)

I have the following code(我有以下代码)

// child component
this.$emit('someEvent', 1, 2, 3)
// parent component
<child @someEvent="handleSomeEvent(arguments, 5,6)"></child>
methods: {
  handleSomeEvent (arg, a, b) {
    console.log(...arg); // 1,2,3
  }
}

I want to know(我想知道)

  1. How does the code work?(代码如何工作?)
  2. Why we can get arguments?(为什么我们可以争论?)

I don't understand the principle, I cannot find answer form source code or internet.(我不了解原理,找不到源代码或互联网的答案。)

can anyone help me explain this, please.(谁能帮我解释一下。)   ask by lijiacong translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

That is how Vue emit works:(这就是Vue emit工作方式:)

vm.$emit(eventName, [...args])

Arguments will be passed into the listener's callback function.(参数将传递到侦听器的回调函数中。)

Everything passed after emitName will be assumed as arguments .(在emitName之后传递的所有内容都将作为arguments 。) Here is the documentation(这是文档)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...