A
A
Anton Anton2017-05-31 14:08:11
Vue.js
Anton Anton, 2017-05-31 14:08:11

How to make a component with reuse of other components?

To use vue with bootstrap I tried bootstrap-vue. in principle, everything worked, I want to make "beauty".
When using vue-router, the router-link component is rendered in when used in the header, the b-nav-item component is rendered in If done manually instead of b-nav-item<a>
<li class="nav-item"><a class="nav-link">

<li class="nav-item"><router-link class="nav-link">
- then everything works.
I wanted to make my own b-router-link component, which would implement this with one tag.
Here is a component that works (without using router-link):
Vue.component('b-router-link', {
  template: '<li class="nav-item"><a class="nav-link"><slot/></a></li>'
})

but this one is not:
Vue.component('b-router-link', {
  template: '<li class="nav-item"><router-link :to class="nav-link"><slot/></router-link></li>'
})

Help me get it right :)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Anton, 2017-05-31
@Fragster

I figured out the correct component is:

Vue.component('b-router-link', {
  template: '<li class="nav-item"><router-link :to="to" class="nav-link"><slot/></router-link></li>',
  props: ['to']
})

usage:
<b-router-link to="/phones">Телефоны</b-router-link>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question