当NUXT-Link处于活动状态时,请更改图标?
我在Navbar中有3个链接,每个链接包含2个图标(假设Icon-1和Icon-2),但是我只想一次显示1个图标。
iCON-1当NUXT-LINK处于活动状态并悬停的
ICON-2当NUXT-Link不活动时,
这是我的代码,
<ul>
<li class="nav-list-item" v-for="(link, i) in navLinks" :key="i">
<nuxt-link :to="link.path">
<img :src="link.inactive"> //this is icon-1
<img :src="link.active"> //this is icon-2
<span class="nav-title">{{link.title}}</span>
</nuxt-link>
</li>
</ul>
这是我的脚本
data() {
return {
navLinks: [
{
title: 'Link 1',
path: '/' ,
inactive: './Icons/home-icon-1.svg',
active: './Icons/home-icon-2.svg'
},
{
title: Link 2',
path: '/about' ,
inactive: './Icons/about-icon-1.svg',
active: './Icons/about-icon-2.svg'
},
{
title: 'link 3',
path: '/contact' ,
inactive: './Icons/contact-icon-1.svg',
active: './Icons/contact-icon-2.svg'
},
]
}
},
I have 3 links in navbar and each link contains 2 icons (lets say icon-1 and icon-2), but i want to show only 1 icon at a time.
icon-1 when nuxt-link is active and hovered
icon-2 when nuxt-link is inactive
this is my code
<ul>
<li class="nav-list-item" v-for="(link, i) in navLinks" :key="i">
<nuxt-link :to="link.path">
<img :src="link.inactive"> //this is icon-1
<img :src="link.active"> //this is icon-2
<span class="nav-title">{{link.title}}</span>
</nuxt-link>
</li>
</ul>
this is my script
data() {
return {
navLinks: [
{
title: 'Link 1',
path: '/' ,
inactive: './Icons/home-icon-1.svg',
active: './Icons/home-icon-2.svg'
},
{
title: Link 2',
path: '/about' ,
inactive: './Icons/about-icon-1.svg',
active: './Icons/about-icon-2.svg'
},
{
title: 'link 3',
path: '/contact' ,
inactive: './Icons/contact-icon-1.svg',
active: './Icons/contact-icon-2.svg'
},
]
}
},
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,您需要在每个链接对象中设置活动状态:
然后,您必须在NUXT链接和逻辑上设置两个本机事件侦听器以显示IMG:
First of all you need to set active state in every link object:
then you must set two native event listeners on nuxt link and logic to show img: