Search code examples
vue.jsvuejs2vue-componentnuxt.jswordpress-rest-api

How to create a dynamic anchor link in nuxt.js?


I'm building a nuxt onepager that is feeded with content from the Wordpress Rest Api.

I'm already getting the Wordpress menu structure and every menu item is stored in {{ item.title }}. To scroll later to the requested div with it's id {{ item.title }} i want to complete the {{ item.title }} with a #.

My idea so far is: <nuxt-link to="'#'{item.title}'" exact class="nav-link">{{ item.title }}</nuxt-link>


Solution

  • You could bind it as follows :

    <nuxt-link :to="'#'+item.title" exact class="nav-link">{{ item.title }}</nuxt-link>