Skip to content

Commit

Permalink
style: 优化 textarea 组件
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyh2001 committed Jun 25, 2023
1 parent ed2735e commit 74478d5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 18 deletions.
2 changes: 1 addition & 1 deletion packages/fighting-design/_utils/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const keepDecimal = (value: number, no = 2): number => {
*/
export const debounce = <T extends (...args: unknown[]) => void>(
func: T,
delay: number
delay = 1000
): ((...args: Parameters<T>) => void) => {
/** 计时器实例 */
let timeout: ReturnType<typeof setTimeout> | undefined
Expand Down
12 changes: 9 additions & 3 deletions packages/fighting-design/textarea/src/textarea.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import { useInput, useList, useRun } from '../../_hooks'
import { FIconCross } from '../../_svg'
import { FSvgIcon } from '../../svg-icon'
import { debounce } from '../../_utils'
import type { WatchStopHandle } from 'vue'
defineOptions({ name: 'FTextarea' })
Expand Down Expand Up @@ -77,15 +78,20 @@
)
}
/** 设置宽度方法 */
const _changeHeight = debounce(changeHeight, 500)
/** 初始化调用 */
onMounted((): void => {
if (prop.autoHeight) {
isAutoHeight()
window.addEventListener('resize', changeHeight)
window.addEventListener('resize', _changeHeight)
}
})
onBeforeUnmount(() => {
window.removeEventListener('resize', changeHeight)
/** 销毁前移除事件 */
onBeforeUnmount((): void => {
window.removeEventListener('resize', _changeHeight)
})
/**
Expand Down
16 changes: 2 additions & 14 deletions start/src/App.vue
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
<script lang="ts" setup>
import { ref } from 'vue'
<script lang="ts" setup></script>

const value1 = ref('')
const show = ref(true)
// setTimeout(() => {
// show.value = false
// }, 2000)
</script>

<template>
<f-textarea v-if="show" v-model="value1" placeholder="请输入...." auto-height />
</template>
<template></template>

0 comments on commit 74478d5

Please sign in to comment.