question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

$emit() doesn't work

See original GitHub issue

clean install and replace with this two components. App.vue ->

<template>
  <view class="container">
    <text class="text-color-primary">My First Text</text>
    <children v-on:custom-event="customEventHandler">
          <text class="text-color-primary">My slot</text>
     <template slot="namedslot">
          <text class="text-color-primary">My slot 2</text>
     </template>
    </children>
    </view>
</template>
 <script>
 import children from './children.vue'
 export default {
   components: {
     children
   },
   methods:{
     customEventHandler(value){
       console.log(value);
     }
   }
 }
 </script>
 
<style>
.container {
  background-color: white;
  align-items: center;
  justify-content: center;
  flex: 1;
}
.text-color-primary {
  color: blue;
}
</style>
```

new children.vue ->

```
<template>
    <view>  
        <button class="text-color-primary" :on-press="click(1)" title="HELLOW"></button>
        <slot></slot>
        <button class="text-color-primary" :on-press="click(2)" title="HELLOW2"></button>
        <slot name="namedslot"></slot>
   </view>
</template>

<script>
export default {
    methods: {
        click(value){
            console.log('childer clicked:'+ value);
            this.$emit('custom-event',value);
        }
    }
}
</script>

<style>
.text-color-primary {
  color: green;
}
</style>
```

App vue doesnt receive anything and the view doesnt show as expected

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:8
  • Comments:13 (5 by maintainers)

github_iconTop GitHub Comments

36reactions
neeraj-singh47commented, Aug 16, 2018

Please upvote the issue if you guys want it to be fixed. As of now, It doesn’t seem to be important since there is a workaround for the $emit.

17reactions
LiveDuocommented, Aug 13, 2018

A quick workaround to invoke functions from childs to parents until $emit is fixed. Allows dumb and smart components to function as expected in Vue Native.

/// Child.vue

<template>
  <view>
    <button title="'button'" :on-press="foo">
  </view>
</template>

<script>
export default {
	props: {
		foo: Function
	}
}
</script>

/// Parent.vue

<template>
	<view>
		<child :foo="foo">
	</view>
</template>

<script>
import Child from './Child.vue'
export default {
	methods: {
		foo() {
			console.log('i am working')
		}
	},
	components: { Child }
}
</script>
Read more comments on GitHub >

github_iconTop Results From Across the Web

Why does $emit not work in my vue component - Stack Overflow
emit() is a way to say to the parent component that hey i created an ... you don't listen in parent component the...
Read more >
basic $emit() function not working - Laracasts
basic $emit() function not working. Im 2 weeks old when it comes to vue. js im struggling since couple of days ago to...
Read more >
$emit not working - Get Help - Vue Forum
$emit is used for child => parent component communication. Dispatching an $emit event won't send it out globally. It will only send the...
Read more >
ParticleEmitter:Emit() doesn't work - Scripting Support
I expected a particle to be emitted as soon as the script run, although I got “emitted” printed to the console, but no...
Read more >
A Guide to Vue $emit - How to Emit Custom Events in Vue
How does Vue Emit Work? When we emit an event, we invoke a ... We are emitting an event called add and passing...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found