জয়েন লগইন

ভিইউই onErrorCaptured

🌈ভিইউই onErrorCaptured কি?

📋ভিইউই onErrorCaptured হলো অধস্তন কম্পোনেন্টের ত্রুটি শনাক্ত করার পদ্ধতি।

⚒️ভিইউই onErrorCaptured অধস্তন কম্পোনেন্টের ত্রুটি শনাক্ত করতে ব্যবহৃত হয়।

ভিইউই onErrorCaptured অধস্তন কম্পোনেন্টের ত্রুটি শনাক্ত করার উদাহরণ।

vue
<!DOCTYPE html>
<html>
<body>

<div id="app">
  <child-component></child-component>
  <p>{{error}}</p>
</div>

<script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
<script>
const {createApp, ref, onErrorCaptured} = Vue;
const ChildComponent = {
  setup() {
    throw new Error("এরর");
  },
  template: "<p>হ্যালো</p>"
};
createApp({
  components: {ChildComponent},
  setup() {
    const error = ref("");
    onErrorCaptured((err) => {
      error.value = err.message;
      return false;
    });
    return {error};
  }
}).mount("#app");
</script>
</body>
</html>