【问题标题】:writing 2 condition in one if vuejs如果 vuejs 将 2 个条件合二为一
【发布时间】:2021-03-09 23:30:57
【问题描述】:

嗨,我有一个代码,我想将 2 个条件放在一个 if 中。我的代码如下:

  <img v-if="attribute.swatch_type == 'color'" class="thumb-product-select" style="width: 80px;height: auto" :src="'storage/' + option.images" alt="">
                             <span  id="color_id_select" v-if='attribute.swatch_type == 'color' && option.images ='20.jpeg')"
                                  :style="{ background: option.swatch_value }">
                            </span>

所以我想说如果 type 是 color 并且 option.images 等于 20.jpeg 然后显示这个 span 。现在我收到很多错误,如下所示:

Property or method "option" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property. See: https://vuejs.org/v2/guide/reactivity.html#Declaring-Reactive-Properties.

found in

---> <ProductOptions>

但正如您在上面看到的那样,我正在使用它,第二个错误是

velocity.js:2771 [Vue warn]: Error in render: "TypeError: Cannot read property 'label' of undefined"

found in

---> <ProductOptions>
       <ProductView>

我不知道为什么会发生这个错误

【问题讨论】:

  • 'attribute.swatch_type == 'color' &amp;&amp; option.images ='20.jpeg' -> "attribute.swatch_type == 'color' &amp;&amp; option.images ='20.jpeg'" 你提前关闭了引号,因为你到处都在使用单引号。
  • 现在我得到这个错误:Invalid left-hand side in assignment in
  • 顺便说一句,如果我这样放置:v-if="attribute.swatch_type == 'color'" 我的意思是单一条件工作正常

标签: javascript vue.js vue-component


【解决方案1】:

检查你的报价,你错过了双等于这里 option.images ='20.jpeg'

应该是

v-if="attribute.swatch_type == 'color' && option.images == '20.jpeg'"

【讨论】:

  • 谢谢你,我错过了你所说的报价,这对我很有帮助,谢谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-09-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多