Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/security/4.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
Json v-if语句比较一个参数,如果匹配,则返回Vue js上同一对象内的另一个参数_Json_Vue.js_Vuejs2_Vue Component - Fatal编程技术网

Json v-if语句比较一个参数,如果匹配,则返回Vue js上同一对象内的另一个参数

Json v-if语句比较一个参数,如果匹配,则返回Vue js上同一对象内的另一个参数,json,vue.js,vuejs2,vue-component,Json,Vue.js,Vuejs2,Vue Component,什么是v-if,我可以使用它在json文件的对象中查找匹配的标题,如果找到了标题,则检索对象内容 下面是我正在使用的json文件示例: { "data": [ { "image_path": "static/products/T130-SHEET-COLLECTION.jpg", "title": "Productivity Tools", &quo

什么是v-if,我可以使用它在json文件的对象中查找匹配的标题,如果找到了标题,则检索对象内容

下面是我正在使用的json文件示例:

{
  "data": [
    {
      "image_path": "static/products/T130-SHEET-COLLECTION.jpg",
      "title": "Productivity Tools",
      "title_color": "badge-warning",
      "heading": "T130 Sheet Collection",
      "read_more_url": "javascript:void(0);",
      "content": "blanket posuere proin blandit accumsan senectus netus nullam curae, ornare laoreet adipiscing luctus mauris adipiscing pretium eget fermentum, tristique lobortis est ut metus lobortis tortor.",
      "vendor": "George Courey",
      "space": "Bedding",
      "category": "Linen"
    },
    {
      "image_path": "static/products/PRESTIGE-PLUS-T180-SHEET-COLLECTION.jpg",
      "title": "Productivity Tools",
      "title_color": "badge-warning",
      "heading": "Prestige Plus T180 Sheet Collection",
      "read_more_url": "javascript:void(0);",
      "content": "blanket posuere proin blandit accumsan senectus netus nullam curae, ornare laoreet adipiscing luctus mauris adipiscing pretium eget fermentum, tristique lobortis est ut metus lobortis tortor.",
      "vendor": "George Courey",
      "space": "Bedding",
      "category": "Linen"
    }
  ]
}

v-if
中的
v-for

<div v-for="item of data">
    <div v-if="item.title === 'condition'">
        {{ item.title }}
    </div>
</div>

{{item.title}

不清楚您的情况如何。你是在匹配重复项还是其他值

无论哪种方式,我都建议您使用
computed
,而不是依赖
v-if
。这有很多好处,比如模板和逻辑的更清晰分离,更容易阅读调试,更容易在js中编写过滤逻辑