javascript - The child component triggers a custom event of the parent component, but the parent component does not respond.
大家讲道理
大家讲道理 2017-07-05 11:03:26
0
3
929

The following are sub-components @change='showChange' is the sub-component event
The following templates are registered as order-type components

The following are sub-component methods:

showChange(event) { for (let branch of this.branchList) { if (branch['id'] === event.target.value) { this.$emit('showChange',branch['prefix']); } }

The following is the parent component

But alert(2) is not executed

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all (3)
女神的闺蜜爱上我

There is something wrong with you just writing it like this
It should be

 父组件有一个方法 methods: { alertFun () { alert(2) } }

What should be passed here is a function name of the parent component method instead of writing alert(2) directly

    女神的闺蜜爱上我

    This should be the problem

      伊谢尔伦

      The following is a sub-component @change='showChange' is a sub-component event
      The following template is registered as an order-type component

      The following are sub-component methods:

      showChange(event) { for (let branch of this.branchList) { if (branch['id'] === event.target.value) { /注意此行的修改/ this.$emit('parentChage',branch['prefix']); } } 以下是父组件  但alert(2) 并未执行
        Latest Downloads
        More>
        Web Effects
        Website Source Code
        Website Materials
        Front End Template
        About us Disclaimer Sitemap
        php.cn:Public welfare online PHP training,Help PHP learners grow quickly!