0

I'm trying to set something up in my app where I can select an option from a list and change the background of the app depending on what's selected.

Let's say I have a list like:

<li v-for="item in items">
 <label class="radio">
 <input type="radio" value="{{ item.name }}" v-model="itemSelection">
 {{ item.name }}
 </label>
</li>

items is an array that's stored in my store.js:

items: [
 {name: 'item1', img: 'placehold.it/200x200-1'}
 {name: 'item2', img: 'placehold.it/200x200-2'}
 {name: 'item3', img: 'placehold.it/200x200-3'}
],

So when you select item1 I want to not only pull the name from the selection (which gets passed up to the parent component in itemSelection to display there) but also the img link to place that in css to change the background of the body. I'm not entirely sure how to go about this, as I'm pretty new to vue and this is basically something I'm building to help me learn!

Thanks!

asked Sep 9, 2016 at 18:07

1 Answer 1

5

You can do this by several ways e.g:

watch : {
 itemSelection: function(val) { ... }
}

There is some examples. Check this fiddle

answered Sep 9, 2016 at 21:04

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.