【发布时间】: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' && option.images ='20.jpeg'->"attribute.swatch_type == 'color' && option.images ='20.jpeg'"你提前关闭了引号,因为你到处都在使用单引号。 -
现在我得到这个错误:Invalid left-hand side in assignment in
-
顺便说一句,如果我这样放置:v-if="attribute.swatch_type == 'color'" 我的意思是单一条件工作正常
-
option.images ='20.jpeg'=is assignment,==or===for equality check
标签: javascript vue.js vue-component