Giter VIP home page Giter VIP logo

Comments (2)

danielstgt avatar danielstgt commented on May 25, 2024 1

This is due to the nature of how Vue handles its diffing, nothing related to SVG Vue.

When v-if is used, the second button isn't rendered, while v-show just sets display: none. That means if the condition for the second button to get rendered is true, Vue will start checking what needs to be changed. Since it already knows the <svg-vue> tag, it just skips it. Again, this applies to every element and isn't specifically a SVG Vue thing.

To get around this, you can use a key attribute.

Based on your example, this version should work with v-if:

<button
    v-if="suggestion.is_archived"
    key="restore"
    class="font-bold py-1 px-2 rounded text-xs bg-gray-200 hover:bg-gray-300 text-gray-600 hover:text-gray-800 space-x-2 flex items-center"
    name="restore-suggestion"
    title="Restore suggestion"
    type="button"
    :disabled="isSaving"
    @click.prevent="setIsArchived(false)">
    <svg-vue class="w-4" icon="restore-small"></svg-vue> <span>Restore</span>
</button>

<button
    v-if="!suggestion.is_archived"
    key="archive"
    class="font-bold py-1 px-2 rounded text-xs bg-gray-200 hover:bg-gray-300 text-gray-600 hover:text-gray-800 space-x-2 flex items-center"
    name="archive-suggestion"
    title="Archive suggestion"
    type="button"
    :disabled="isSaving"
    @click.prevent="setIsArchived(true)">
    <svg-vue class="w-4" icon="archive-small"></svg-vue> <span>Archive</span>
</button> 

Just remember that keys have to be unique, Vue has to distinguish by their name.

However, I would actually recommend to use v-show in this case, the rendering cost is lower when toggling between the two states, also no key is needed since the buttons just change their visibility via styling (display: none state).

I will add a note in the readme depending on your case, since toggling icons isn't that uncommon.

from laravel-mix-svg-vue.

danielbachhuber avatar danielbachhuber commented on May 25, 2024

Thanks @danielstgt ! This makes sense to me, and I appreciate you taking the time to explain in such detail.

from laravel-mix-svg-vue.

Related Issues (12)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.