pages/index.vue
<template>
<Toast2 ref="toast2" />
<button style="margin-top:100px" @click="()=>toast2.showit()">显示</button>
</template>
<script lang="ts">
import {
ref
} from 'vue';
import Toast2 from '@/components/Toast2.vue';
export default {
components: {
Toast2
},
setup() {
const toast2 = ref(null);
return {
toast2
}
},
};
</script>
/components/Toast2.vue
<template>
<view :class="['toast', cls]">测试来了</view>
</template>
<script lang="ts">
import {
ref
} from 'vue';
export default {
setup() {
let id = 0;
const cls = ref('');
const showit = function () {
clearTimeout(id);
cls.value = 'toast-show';
id = setTimeout(() => {
cls.value = '';
}, 1000);
};
return {
cls,
showit
}
}
}
</script>
<style>
.toast {
position: fixed;
z-index: 1002;
left: 50%;
top: 50%;
background: #210e3bc4;
border-radius: 8rpx;
color: #fff;
padding: 30rpx 60rpx;
font-size: 36rpx;
opacity: 0;
white-space: nowrap;
border: solid 1px #2b294f;
pointer-events: none;
}
.toast-show {
opacity: 1;
display: block;
}
</style>
s***@163.com (作者)
点击第2次后,很久才显示消息
2022-09-23 12:14
s***@163.com (作者)
可以点击上面链接查看录屏效果
2022-09-23 13:44
s***@163.com (作者)
性能如此的差,真是晕死
2022-09-23 18:40