<script setup>import { reactive, onBeforeUnmount } from 'vue';const record = reactive({});onBeforeUnmount(() => {for (const key in record) {delete record[key];}});</script>在`onBeforeUnmount`钩子函数中,你可以遍历`record`对象的属性,并使用`delete`关键字来删除属性,从而清空`record`对象。
Vue.js 页面关闭时清空数据 - 使用 beforeUnmount 钩子函数

原文地址: https://www.cveoy.top/t/topic/pwzl 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录