Vue.js 如何设置 :id 前缀字符串? [英] Vue.js how to set :id prefix string?

查看:45
本文介绍了Vue.js 如何设置 :id 前缀字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

我在一个 vue 社区中找到了这个例子,但在我的情况下,我希望我的id"有一个前缀,而不仅仅是一个数字.

也就是说,如果索引为1,我想要 而不是.

解决方案

你可以这样做,代码应该是不言自明的:

<span :id="'sp_' + index">{{tabTitle}} </span>

文档链接.

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>.

解决方案

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.

这篇关于Vue.js 如何设置 :id 前缀字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆