| 事件名称 | 何时触发 |
|---|---|
[error](https://developer.mozilla.org/zh-CN/docs/Web/Reference/Events/error) |
资源加载失败时。 |
[abort](https://developer.mozilla.org/zh-CN/docs/Web/Reference/Events/abort) |
正在加载资源已经被中止时。 |
[load](https://developer.mozilla.org/zh-CN/docs/Web/Reference/Events/load) |
资源及其相关资源已完成加载。 |
[beforeunload](https://developer.mozilla.org/zh-CN/docs/Web/Reference/Events/beforeunload) |
window,document 及其资源即将被卸载。 |
[unload](https://developer.mozilla.org/zh-CN/docs/Web/Reference/Events/unload) |
文档或一个依赖资源正在被卸载。 |
beforeunload 页面卸载前
window,document 及其资源即将被卸载时触发。
🌰 :Vue中某表单页退出页面时提示
mounted() {console.info(this.$route);// 浏览器刷新 || 关闭浏览器 时提示// let _this = this;// window.onbeforeunload = function (e) {// if (_this.$route.name == "Newsign") {// e = e || window.event;// // 兼容IE8和Firefox 4之前的版本// if (e) {// e.returnValue = "关闭提示1111";// }// // Chrome, Safari, Firefox 4+, Opera 12+ , IE 9+// return "关闭提示222";// } else {// window.onbeforeunload = null;// }// };},beforeRouteLeave(to, from, next) {// 点击其他tabview || 关闭当前tabview时提示// const answer = window.confirm('确定要离开当前页面?')// if (answer) {// next()// } else {// next(false)// }},
DOMContentLoaded
document.addEventListener('DOMContentLoaded', () => {Vue.createApp({data() {return {todayAmount: '0',platformSales1: 4090013,}},computed: {todayAmountComputed() {return this.todayAmount.split('');},},mounted() {setInterval(() => {if (this.todayAmount === '0') {this.todayAmount = '1000';}this.todayAmount = '' + Math.floor(Math.random() * 10000);}, 2000);},}).mount('#app');})
