0

Tables hidden by the v-if directive, except for tables visible when loading the page for the first time, cannot be 'css+js' controlled. If I delete all the 'v-if, everything works. Maybe it seems that only the first 0 of the for statement is executed.

What could be the problem?

This is the HTML code-

<div class="machine_w state" id="ss0">기기 상태</div>
<div class="machine_w time table" id="t0">압력 센서 상태</div>
<div class="machine_w total_user_time" id="a0">알람 상태</div>

This is the script code-

  methods: {
    vacuum_status() {
      for (var i = 0; i < 4; i++) {
        if (this.$store.state.mqtt_data_arr[i].vacuum_status == 1) {
          document.getElementById(`t${i}`).style.backgroundColor = "#e96666";
          alert(
            `${this.$store.state.mqtt_data_arr[i].device_name}호기 압력센서 비정상`
          );
          return;
        } else if (this.$store.state.mqtt_data_arr[i].vacuum_status == 0) {
          document.getElementById(`t${i}`).style.backgroundColor = "#3baf4a";
        }
      }
    },
}
1
  • 1
    your working with vue you don't really need document.getElementById you can toggle a class or set styles when you loop over mqtt_data_arr, i.e :style="item.vacuum_status ? '#e96666' : '#e96666'" if you show more of the template including the loop should get a better answer Commented Dec 9, 2022 at 10:33

1 Answer 1

1

Because the element that is not rendered by v-if, does not exist on the page. It means there is no any selector.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.