Combining v-for with v-show on same element in template

Asked By: Anonymous

I want to display a list of entries, and I have it working up through retrieving JSON from a server, parsing it, storing it in a Vuex.Store and iterating through it with v-for-"entry in this.$store.state.entries".

When a user first visits the page all entries will be visible. The next step is to filter the entries so that only matching entries remain visible. Since this filtering will be changing a lot, I want to use v-show. I have a separate component that lets users enter search terms, the server is queried, and an array of numbers—matching IDs—is returned. I want to only show entries with IDs that match the numbers in the array, queriedEntries. My template is below:

<template>
    <div id="entries">
        <div v-for="entry in this.$store.state.entries"
            v-html="entry.content"
            v-show="this.$store.state.queriedEntries.includes(entry.id)">
        </div>
    </div>
</template>

I get an error that I don’t understand, and searching for answers hasn’t yielded anything because it doesn’t match the problem others have had.

[Vue warn]: Error in render: "TypeError: this is undefined"

It’s the this in the v-show, but every other this works. What’s up?


Solution

Answered By: Anonymous

I ended up removing this from everything but the v-for, as suggested, and the code worked. Why this causes an error in v-show and v-html is still a mystery.

Final, working code:

<div v-for="(entry, entryindex) in this.$store.state.entries"
 v-bind="{id:entryindex}"
 v-bind:key="entryindex" 
 v-show="$store.state.queryMatchedEntries[0] == -1 || $store.state.queryMatchedEntries.indexOf(parseInt(entryindex)) != -1">

Windows 10 Kaufen Windows 10 Pro Office 2019 Kaufen Office 365 Lizenz Windows 10 Home Lizenz Office 2019 Home Business Kaufen windows office 365 satın al follower kaufen instagram follower kaufen porno