Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vue.js/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vue.js v-for显示顶级v-if中应跳过的项目_Vue.js - Fatal编程技术网

Vue.js v-for显示顶级v-if中应跳过的项目

Vue.js v-for显示顶级v-if中应跳过的项目,vue.js,Vue.js,我有下一个代码: <div v-for="question in questions"> <h3 v-if="question.isEnabled">{{question.question}}</h3> <div v-for="answers in question.answers"> <h4>{{answers.answer}}</h4> </div

我有下一个代码:

  <div v-for="question in questions">
      <h3 v-if="question.isEnabled">{{question.question}}</h3>
        <div v-for="answers in question.answers">
          <h4>{{answers.answer}}</h4>
        </div>
  </div>  

{{问题.问题}
{{答案。答案}
它应该只打印
问题。isEnabled
问题。在下一次迭代中,它应该打印他们的答案。打印的问题甚至回答了
问题中未显示的问题。isEnabled
条件

它看起来像:


试试
filterBy

<div v-for="question in questions | filterBy true in isEnabled">
        <h3>{{question.question}}</h3>
        <div v-for="answers in question.answers">
           <h4>{{answers.answer}}</h4>
        </div>
    </div>

{{问题.问题}
{{答案。答案}

试试
filterBy

<div v-for="question in questions | filterBy true in isEnabled">
        <h3>{{question.question}}</h3>
        <div v-for="answers in question.answers">
           <h4>{{answers.answer}}</h4>
        </div>
    </div>

{{问题.问题}
{{答案。答案}

具体问题是
v-if
是一个指令,因此它必须附加到一个元素上,并且只影响该元素。因此,您的代码按spected运行,因为它仅在条件为true时显示
h3
元素

在这种情况下,您需要使用


{{问题.问题}
{{答案。答案}

具体问题是
v-if
是一个指令,因此它必须附加到一个元素上,并且只影响该元素。因此,您的代码按spected运行,因为它仅在条件为true时显示
h3
元素

在这种情况下,您需要使用


{{问题.问题}
{{答案。答案}

使用您的代码我得到:
未捕获类型错误:无法读取未定义的属性“trim”
使用您的代码我得到:
未捕获类型错误:无法读取未定义的属性“trim”