Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vue.js how to set :id prefix string?

Tags:

vue.js

vuejs2

class="tab-title" 
v-on:click="tab" 
v-for="(tabTitle,index) in tabTitleList"
:id="index"

I found this example in an vue community, but in my situation, I want my "id" has a prefix, not just a number.

That is to say, if the index is 1, I want <span id='sp_1'></span> instead of <span id='1'></span>.

like image 378
wtf512 Avatar asked Dec 24 '16 10:12

wtf512


People also ask

What is $t in Vuejs?

Vuex is a state management pattern for vue. js. $t is the injected method from vue. js or Vue.

What is a Vue ID?

A digital ID is a safe way to prove your age and identity using your phone – online and in person. It takes just minutes to create and then you're set up for life. You can now use Yoti, a free to use app to obtain a Digital ID to prove your age at Vue Cinemas across the UK & Ireland.

How does one assign directive in Vue?

Using the v-if , v-else , and v-else-if Directives. Vue. js comes pre-packaged with a number of directives that developers commonly use when working within the framework. Directives such as v-if , v-show , v-on , v-model , v-bind , v-html , and more are all provided for you out-of-the-box.

How do I declare a variable in the method Vuejs?

if you define global variable then you can easily access global variable in vuejs app. We will define global variables using vue js mixin. using mixin we will declare all variables in data method. then we will use in our app vue object.


1 Answers

You can just do, code should be self explanatory:

<div v-for="(tabTitle, index) in tabTitleList">
    <span :id="'sp_' + index"> {{tabTitle}} </span>
</div>

Documentation link.

like image 175
Saurabh Avatar answered Sep 17 '22 14:09

Saurabh