A
A
Alexander2020-05-16 17:08:29
Vue.js
Alexander, 2020-05-16 17:08:29

How to combine 2 v-ifs in vuejs?

Hello, there was a need to combine 2 v-if into 1. Here is the code itself:

<img v-if="wall.users.photo" :src=" wall.users.photo " alt="">
<img v-if="wall.pages.photo" :src=" wall.pages.photo " alt="">


If for example wall.users.photo = null then we load wall.pages.photo and vice versa.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2020-05-16
@AlexVue

<img :src="wall.users.photo || wall.pages.photo">
If the presence of at least one of the values ​​is suddenly not guaranteed, then:

computed: {
  src() {
    const { wall } = this;
    return wall.users.photo || wall.pages.photo;
  },
},

<img v-if="src" :src="src">

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question