A
A
alex2018-08-17 14:52:14
Vue.js
alex, 2018-08-17 14:52:14

Adding attributes dynamically?

I'm trying to do something like this:
there is a variable isLink, it is either trueeither false
depending on the value of the variable, you need to render
<div class="link">контент</div>
either

<router-link to="/path" class="link">контент</router-link>

Tried to do like this:
<component :is="isLink ? 'router-link' : 'div'" to="/path">

But in the end, if isLink === false:
<div class="link" to="/path">контент</div>
Is it possible to somehow dynamically attach an attribute to an element depending on the conditions?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir Proskurin, 2018-08-17
@potapchino

Why not do so?

<router-link to="/path" class="link" v-if"isLink">контент</router-link>
<div class="link" to="/path" v-else>контент</div>

R
Roman Kitaev, 2018-08-17
@deliro

Can. Create a component from a div

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question