[Vuejs]-How do I track data changes in external file with composition APi in Vue 3

1👍

You should create composable:

system.js

export function useSystem() {
  const loginStatus = ref(false);

  return {
    loginStatus
  }  
}

App.vue

<template>
  <div v-if="loginStatus"> ...
</template>

<script>
import { useSystem } from "./system.js";

export default {
  setup() {
    init();
    const { loginStatus } = useSystem();

    watch(loginStatus, (currentValue) => {
        ...
    });

    return {    
      loginStatus      
    };
  },
};
</script>
👤Kuban

Leave a comment