简体   繁体   English

如果在vue列表中的每个项目上都不同

[英]Different if on each item in a vue list

I'm making a list with 'v-for' where each item has to have an if with a different value corresponding the array, but the Vue not allows to create a 'v-if' expression starting from {{ i.some_data_to_evaluate }} . 我正在用“ v-for”创建一个列表,其中每个项目都必须有一个if,该if具有与数组对应的不同值,但是Vue不允许从{{i.some_data_to_evaluate}开始创建“ v-if”表达式}。

Have a way to solve this? 有办法解决吗?

Here is my code: 这是我的代码:

HTML 的HTML

<div id='test' v-for="i in items"> 
  <p v-if={{i.value}}>{{i.some_text}}</p>
  <p v-else>{{i.other_text}}</p>
</div>

JS JS

let test = new Vue({
  el: '#test',
  data: [
  {some_text: 'jhon', other_text: 'jonas', value:false},
  {some_text: 'joao', other_text: 'maria', value:true}
 ]
})

I'm just trying to change the version that is in the Vue guide. 我只是想更改Vue指南中的版本。

Here's the link: http://vuejs.org/guide/list.html 这是链接: http : //vuejs.org/guide/list.html

You should replace the brackets with quotes on the v-if directive: 您应该用v-if指令上的引号替换括号:

<div id="test" v-for="i in items"> 
  <p v-if="i.value">{{i.some_text}}</p>
  <p v-else>{{i.other_text}}</p>
</div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM