Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

boyjarv's avatar

bodyContent not showing

$data._slideIndex = 0

{{ $data._slideIndex }}
        <div ref="bodyContent" class="ins phone-ins" v-html="element.content.ins" v-if="$data._slideIndex === 0 && $store.state.device === 'phone' || $data._slideIndex === element.content.slides.length-1 && $store.state.device === 'phone'" />

bodyContent only shows if the page is refreshed and $data._slideIndex is equal to 0

0 likes
2 replies
LaryAI's avatar
Level 58

It seems like the issue is with the conditional rendering of the bodyContent element. It is only being rendered if $data._slideIndex is equal to 0 and $store.state.device is equal to 'phone', or if $data._slideIndex is equal to the length of element.content.slides minus 1 and $store.state.device is equal to 'phone'.

One possible solution is to use a computed property to determine whether or not to render the bodyContent element. This computed property can check if $data._slideIndex is equal to 0 and $store.state.device is equal to 'phone', or if $data._slideIndex is equal to the length of element.content.slides minus 1 and $store.state.device is equal to 'phone', and return a boolean value accordingly.

Here's an example of how this can be implemented:

<template>
  <div>
    {{ $data._slideIndex }}
    <div ref="bodyContent" class="ins phone-ins" v-html="element.content.ins" v-if="shouldRenderBodyContent" />
  </div>
</template>

<script>
export default {
  computed: {
    shouldRenderBodyContent() {
      return (
        ($data._slideIndex === 0 && $store.state.device === 'phone') ||
        ($data._slideIndex === element.content.slides.length - 1 && $store.state.device === 'phone')
      );
    },
  },
};
</script>

In this example, we've created a computed property called shouldRenderBodyContent that checks if $data._slideIndex is equal to 0 and $store.state.device is equal to 'phone', or if $data._slideIndex is equal to the length of element.content.slides minus 1 and $store.state.device is equal to 'phone'. If either of these conditions is true, the computed property returns true, which causes the bodyContent element to be rendered.

By using a computed property, we can ensure that the bodyContent element is rendered whenever the conditions for rendering it are met, even if the component is not refreshed.

MaverickChan's avatar

if i understand right, you are missing () in conditions , and not suggested to do so in-line , make a computed property

{{ $data._slideIndex }}
        <div ref="bodyContent" class="ins phone-ins" v-html="element.content.ins" v-if="($data._slideIndex === 0 && $store.state.device === 'phone') || ( $data._slideIndex === element.content.slides.length-1 && $store.state.device === 'phone')" />

Please or to participate in this conversation.