-1

hi i have a code that i want to put 2 conditions in one if . my code is like below :

  <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>

so i want to say that if type is color and option.images equals to 20.jpeg then show this span . now i am getting many errors like below :

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>

but as you can see its defined up above and i am using it and the second error is

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

found in

---> <ProductOptions>
       <ProductView>

i dont know why this error happens

Farshad
  • 1,553
  • 4
  • 26
  • 47
  • `'attribute.swatch_type == 'color' && option.images ='20.jpeg'` -> `"attribute.swatch_type == 'color' && option.images ='20.jpeg'"` you're closing the quotes early because you're using single quotes everywhere. – VLAZ Nov 27 '20 at 06:37
  • now i get this error : Invalid left-hand side in assignment in – Farshad Nov 27 '20 at 06:42
  • by the way if i place it like this : v-if="attribute.swatch_type == 'color'" i mean the single condition works fine – Farshad Nov 27 '20 at 06:43
  • `option.images ='20.jpeg'` [`=` is assignment, `==` or `===` for equality check](https://stackoverflow.com/questions/11871616/in-javascript-vs/) – VLAZ Nov 27 '20 at 06:43
  • Does this answer your question? [How to specify multiple conditions in an if statement in javascript](https://stackoverflow.com/questions/8710442/how-to-specify-multiple-conditions-in-an-if-statement-in-javascript) – Abdulla Nilam Nov 27 '20 at 06:48

1 Answers1

2

check your quotes & You missed double equals to here option.images ='20.jpeg'

It should be

v-if="attribute.swatch_type == 'color' && option.images == '20.jpeg'"
Abdulla Nilam
  • 31,770
  • 15
  • 58
  • 79
ROHIT PATIL
  • 36
  • 1
  • 3