-1

What I need is to change the color of links when scrolling up and down. How can I select Link 1/2/3 by using ref?

<nav class="header-nav">
   <ul>
     <li class="tablet-sm-hide">
       <router-link to="/">Link 1 </router-link>
     </li>
     <li class="tablet-sm-hide">
       <router-link to="/">Link 2  </router-link>
     </li>
     <li class="tablet-sm-hide">
       <router-link to="/">Link 3 </router-link>
     </li>
       </ul>

</nav>
Diana
  • 35
  • 1
  • 5

2 Answers2

0

You have access to your refs by using this.$refs.

example

const anchors = this.$refs["a"];

console.log(anchors);
Maik Lowrey
  • 15,957
  • 6
  • 40
  • 79
0

Use this method

this.$refs["n1"].$el.style.color = 'red'
this.$refs["n2"].$el.style.color = 'green'
this.$refs["n3"].$el.style.color = 'blue'
<nav class="header-nav">
    <ul>
        <li class="nav">
            <router-link to="/" ref="n1">Link 1 </router-link>
        </li>
        <li class="nav">
            <router-link to="/" ref="n2">Link 2  </router-link>
        </li>
        <li class="nav">
            <router-link to="/" ref="n3">Link 3 </router-link>
        </li>
    </ul>
</nav>
GMKHussain
  • 3,342
  • 1
  • 21
  • 19