search

Home  >  Q&A  >  body text

javascript - How to pass parameters from sub-component to parent component in Vue

给我你的怀抱给我你的怀抱2813 days ago845

reply all(8)I'll reply

  • 仅有的幸福

    仅有的幸福2017-05-19 10:22:59

    1. EventBus (a situation without event binding that does not quite meet the requirements of the question)

    2. Vuex

    reply
    0
  • 我想大声告诉你

    我想大声告诉你2017-05-19 10:22:59

    dispatch

    reply
    0
  • 習慣沉默

    習慣沉默2017-05-19 10:22:59

    Father-child component communication

    reply
    0
  • 阿神

    阿神2017-05-19 10:22:59

    $emit()

    reply
    0
  • 滿天的星座

    滿天的星座2017-05-19 10:22:59

    The child component uses v-on to listen to an event, and then when it is triggered, it sends the event, which is $emit. Then the parent component also uses v-on to listen to the event you send, and then executes the event defined by your parent component.

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-05-19 10:22:59

    The person above has made it clear, I’m here to make up for it
    child.vue

    <template>
        <p id="test">向父传递</p>
    </template>
    <script>
        export default {
            methods: {
                $('#test').click(()=>{
                    this.$emit('data', '这是我要传的参数');
                })
            }
        }
    </script>

    parent.vue

    <template>
        <child @data="fnSS"></child>
    </template>
    <script>
        import child from './child';
        export default {
            components: {
                tagInput
            }
            methods: {
                fnSS(value) {
                    alert(value);
                },
            }
        }
    </script>

    reply
    0
  • 仅有的幸福

    仅有的幸福2017-05-19 10:22:59

    $emit()

    reply
    0
  • 迷茫

    迷茫2017-05-19 10:22:59

    Subcomponent this.$emit("event",data)

    Parent component @event

    reply
    0
  • Cancelreply