vue中v-for怎么切割字符串
spilt拆分成数组data(){return {val : '223,4456,7849,2298'}}<span v-for="item in val.spilt(',')">{{item}}<span>有时候后端给的数据最后也有个逗号呢?data(){return {val : '223,...
·
spilt拆分成数组
data(){
return {
val : '223,4456,7849,2298'
}
}
<span v-for="item in val.spilt(',')">{{item}}<span>
有时候后端给的数据最后也有个逗号呢?
data(){
return {
val : '223,4456,7849,2298,'
}
}
<span v-for="item in val.spilt(',')">{{item}}<span>
<!-- 输出 -->
<span>223</span>
<span>4456</span>
<span>7849</span>
<span>2298</span>
<span></span>
可是我不想要最后有一个空着的span怎么办呢?
这样写:
<span v-for="item in val.spilt(',')" v-if="item ? item : '' ">{{item}}<span>
<!-- 输出 -->
<span>223</span>
<span>4456</span>
<span>7849</span>
<span>2298</span>
<!-- -->
判断一下span是否有值,有值的情况才输出就可以啦!
更多推荐
已为社区贡献8条内容
所有评论(0)