[Vuejs]-Watch for Store to change with If statement and Await

0👍

Was able to achieve desired results with the following, using @user1854438 help.

Storing {data} as a store to be able to access inside template and outside of the block.

<script setup>
//import Store Data
import { useAppStore } from '~/store/app';

//set Store as a Constant
const appStore = useAppStore();

const supabase = useSupabaseClient();

watch(
  () => appStore.storeID,
  async () => {
    // added async keyword here
    if (appStore.storeID > 0) {
      const { data } = await supabase
        .from('productinfo_testv12')
        .select('*')
        .eq('id', appStore.storeID); // added the value of storeID to the query
      appStore.updateDataID(data);
    }
  }
);
</script>

Leave a comment