javascript - Call parent method with component -


i have component , want add click listener runs method in parent template in vue. possible?

<template>     <custom-element @click="somemethod"></custom-element> </template>  <script>     export default {         name: 'template',         methods: {             somemethod: function() {                 console.log(true);         }     } </script> 

directly vue documentation (https://vuejs.org/v2/guide/components.html#composing-components):

in vue, parent-child component relationship can summarized props down, events up. parent passes data down child via props, , child sends messages parent via events...

so need emit click event child component when happens, can used call method in parent template.

if don't want explicitly emit event child (using this.$emit('click') child component), can try use native click event, @click.native="somemethod" (docs: https://vuejs.org/v2/guide/components.html#binding-native-events-to-components)


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -