Skip to content

Commit 82e057f

Browse files
committed
add toggling and rendering note
1 parent d1f888d commit 82e057f

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,34 @@ Option | Type | Default | Description
101101
`svgPath` | String | `resources/svg` | Path to your SVG files
102102
`extract` | Boolean | `false` | Separate the SVG's from your main bundle
103103
`svgoSettings` | Array | <code>[{&nbsp;removeTitle:&nbsp;true&nbsp;}, {&nbsp;removeViewBox:&nbsp;false&nbsp;}, {&nbsp;removeDimensions:&nbsp;true&nbsp;}]</code> | SVGO settings
104+
105+
#### Toggling icons or rendering inside lists
106+
107+
Not really related to SVG Vue, but when more than one `<svg-vue>` icon is rendered inside a conditional state with `v-if` or `v-for`, a `key` attribute should be used to tell Vue that an element needs to change when any condition changes.
108+
109+
While in most cases the cost for toggling elements with `v-show` should be preferred (also no need for a `key` attribute then), a simple example when toggling an icon with `v-if` inside a button could look like this:
110+
111+
```html
112+
<button v-if="active" key="active-btn">
113+
<svg-vue icon="active-icon" class="..."></svg-vue>
114+
<span>Active</span>
115+
</button>
116+
117+
<button v-if="inactive" key="inactive-btn">
118+
<svg-vue icon="inactive-icon" class="..."></svg-vue>
119+
<span>Inactive</span>
120+
</button>
121+
```
122+
123+
Rendering lists could be handled like this:
124+
125+
```html
126+
<ul>
127+
<li v-for="item in items" :key="item.id">
128+
<p>{{ item.title }}</p>
129+
<svg-vue :icon="item.icon" class="..."></svg-vue>
130+
</li>
131+
</ul>
132+
```
133+
134+
Just remember the `key` has to be unique. More examples for this can be found in the Vue documentation.

0 commit comments

Comments
 (0)