| 1234567891011121314151617181920212223242526272829303132333435363738394041 |
- <template>
- <template v-if="shouldShow">
- <slot />
- </template>
- </template>
- <script setup lang="ts">
- import { ref, computed, onMounted, onUnmounted } from 'vue';
- const props = defineProps({
- minWidth: {
- type: Number,
- default: undefined
- },
- maxWidth: {
- type: Number,
- default: undefined
- }
- })
- const shouldShow = ref(true)
- function checkWidth() {
- const width = uni.getSystemInfoSync().windowWidth
- shouldShow.value = (props.minWidth === undefined || width >= props.minWidth) && (props.maxWidth === undefined || width <= props.maxWidth)
- }
- checkWidth()
- let resizeListener: any
- onMounted(() => {
- resizeListener = () => checkWidth()
- uni.onWindowResize && uni.onWindowResize(resizeListener)
- })
- onUnmounted(() => {
- uni.offWindowResize && uni.offWindowResize(resizeListener)
- })
- </script>
- <style lang="scss" scoped>
- @import "@/uni.scss";
- </style>
|