Comments (2)
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.
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)
- Error: You may need an appropriate loader to handle this file type HOT 1
- Prevent from stripping svg attributes HOT 2
- Update svgo version by deprecated utility HOT 4
- How to use removeAttrs
- Unique IDs HOT 2
- Laravel Mix 6 + Vue 3 Support HOT 4
- Handle style tags inside svg HOT 5
- Vue 3 without options API HOT 5
- How to use with Jetstream(Inertia) HOT 2
- Issues with Laravel Mix 6.0.20 and above? HOT 14
- Prevent from stripping viewBox HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from laravel-mix-svg-vue.