Why does Vue v-on:click is not working on component ?

Why does Vue v-on:click is not working on component ?

Asked on November 15, 2018 in vue.js.
Add Comment


  • 2 Answer(s)
      • If you want to listen to a native event on the root element of a component

     

      • Use the native modifier for v-on like following

     

    <template>
        <div id="app">
            <test v-on:click.native="testFunction"></test>
        </div>
    </template>
    

    Or in shorthand, as suggested in comment, you can as well do:

    <template>
        <div id="app">
            <test @click.native="testFunction"></test>
        </div>
    </template>
    
    Answered on November 15, 2018.
    Add Comment
    • The $emit function works better for which i think you’re asking for.
    • It keeps your component separated from the Vue instance
    • So that it is reusable many contexts.
    •  

     

    <template>
        <div id="app">
            <test @click="$emit('test-click')></test>
        </div>
    </template>
    
    • Use it in HTML
    <test @test-click="testFunction">
    
    Answered on November 15, 2018.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.