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.

How to handle search with $emit value?

See original GitHub issue

I have search input field in header component. I’m getting emitted value but it’s doesn’t filter content. How do i pass $fetch with $emit from header component or what is the right way?

Index.vue

import Header from '@/components/layout/header';
export default {
  components: {
    Header
  },
  data() {
    return {
      posts: [],
      q: ''
    }
  },
  async fetch() {
    this.posts = await this.$content('posts')
    .search(this.q)
    .fetch()
  }
}

Header.vue

<template>
<div>
<input type="search" placeholder="Type your search" v-model="q" @input="$emit('q', $event)">
</div>
</template>
<script>
export default {
  props: [ 'q' ]
}
</script>

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Atinuxcommented, May 25, 2020

Then you need to add a method onSearch to update q and call fetch() again

0reactions
Atinuxcommented, May 26, 2020

I think that you can call this.$fetch() instead of this.$content('posts')..

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Emit Data in Vue: Beyond the Vue.js Documentation
In this blog, we learn how to emit events from child components in Vue, as well as how to emit from nested child...
Read more >
Emit Observable value and handle it in component
What I want is to emit value from login() method in AuthService to handle value in NavbarComponent , however value of appUser$ is...
Read more >
Component Events | Vue.js
A component can emit custom events directly in template expressions (e.g. in a v-on ... It's sometimes useful to emit a specific value...
Read more >
What you should know about Vue v-model - LearnVue
One way to ensure that our value is handled as a Number is to use the ... When we use a custom model...
Read more >
Form Input | Components - BootstrapVue
update. value - Value of input, after any formatting. Not emitted if the value does not change. Emitted to update the v-model ...
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