1

I have this in my HTML page :

<div class="hello">
  <img @mouseover="hover='A'" @mouseleave="hover=''" src="a.png" alt="A" />
  <img @mouseover="hover='B'" @mouseleave="hover=''" src="b.png" alt="B" />
  <br /><br />
  <span>{{ hover }}</span>
</div>

and this in my script :

var hello = new Vue({
  el: ".hello",
  data: {
      hover: ''
  }
});

But the text does not change when I hover an image. I tried with a <span> wrapping each image, but it does not work either.

What do I do?

1
  • Even if Neves' solution is correct, it is more or less what I already had done. The problem was caused by the <div> being wrapped in another <div>, to which a Vue object was applied. (I don't know if it's understandable, sorry for my bad English) Commented Nov 11, 2016 at 15:22

1 Answer 1

4

new Vue({
  el: '.hello',
  data: {
    hover: ''
  }
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.0.5/vue.min.js"></script>
<div class="hello">
  <img @mouseover="hover='A'" @mouseleave="hover=''" src="http://lorempixel.com/400/200/sports/1" alt="a">
  
  <img @mouseover="hover='B'" @mouseleave="hover=''" src="http://lorempixel.com/400/200/sports/2" alt="B">
  
  <br>
  
  <span>Hover: {{ hover }}</span>
</div>

Sign up to request clarification or add additional context in comments.

1 Comment

It was exactly what I had done... except I was wrapping it in another <div> in order to apply a dynamic style with Vue.

Your Answer

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.