본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

PullRefresh

원문 보기 위키 갱신

PullRefresh (당겨서 새로고침)

목록을 아래로 당겨서 새로 고침하는 인터랙션을 제공하는 컴포넌트예요. 새로 고침 작업이 끝나면 v-model을 false로 돌려 로딩 상태를 리셋하는 게 사용 패턴의 핵심이에요.

출처: 문서

본문

소개 (Intro)

당겨서 새로 고침하는 인터랙션 작업을 제공해요.

설치 (Install)

import { createApp } from 'vue'
import { PullRefresh } from '@nutui/nutui'

const app = createApp()
app.use(PullRefresh)

기본 사용법 (Basic Usage)

당겨서 새로 고침하면 refresh 이벤트가 발생해요. refresh 이벤트 처리가 끝나면 v-model을 false로 설정해 로딩 상태를 리셋해야 해요.

:::demo

<template>
  <nut-pull-refresh v-model="refresh" @refresh="refreshFun">
    <div>Try to pull down!</div>
    <div v-for="(item, index) in 24" class="test">{{ index }}</div>
  </nut-pull-refresh>
</template>

<script setup>
import { ref } from 'vue'
const refresh = ref(false)
const refreshFun = () => {
  setTimeout(() => {
    refresh.value = false
  }, 3000)
}
</script>

<style>
.test {
  padding: 12px 0 12px 20px;
  border-top: 1px solid #eee;
}
</style>

:::

커스텀 안내 문구 (Custom Tips)

당겨서 새로 고침에는 'loading' | 'loosing' | 'pulling' | 'complete' 네 가지 상태가 있어요. 각각 pullingTxt、loosingTxt、loadingTxt、completeTxt 속성에 대응하고, 복잡한 스타일은 슬롯으로 구현할 수 있어요。

:::demo

<template>
  <nut-pull-refresh
    v-model="refresh2"
    loosing-txt="Relax"
    loading-txt="Desperate loading..."
    :complete-duration="1000"
    @refresh="refreshFun"
  >
    <template #pulling-txt>
      <div>Pull</div>
    </template>
    <div>Try to pull down!</div>
    <div v-for="(item, index) in 24" class="test">{{ index }}</div>
  </nut-pull-refresh>
</template>

<script setup>
import { ref } from 'vue'
const refresh = ref(false)
const refreshFun = () => {
  setTimeout(() => {
    refresh.value = false
  }, 3000)
}
</script>

<style>
.test {
  padding: 12px 0 12px 20px;
  border-top: 1px solid #eee;
}
</style>

:::

리스너 커스터마이즈 (Customize the listener)

PullRefresh의 트리거 조건은 다음과 같아요. 스크롤 Element의 스크롤바가 꼭대기에 있을 때 부모 위치가 트리거 조건이 되고, 스크롤 Element의 부모가 overflowY: scroll | auto | overlay 설정 여부로 판단해요. 부모 Element가 비어 있으면 트리거 조건은 Element. The scrollTop = = = 0이 돼요.

:::demo

<template>
  <div class="parentpage">
    <nut-pull-refresh v-model="refresh" @refresh="refreshFun">
      <div v-for="(item, index) in 24" class="test">{{ index }}</div>
    </nut-pull-refresh>
  </div>
</template>

<script setup>
import { ref } from 'vue'
const refresh = ref(false)
const refreshFun = () => {
  setTimeout(() => {
    refresh.value = false
  }, 3000)
}
</script>

<style>
.test {
  padding: 12px 0 12px 20px;
  border-top: 1px solid #eee;
}
</style>

:::

API

Props

Attribute Description Type Default
v-model Loading status boolean false
pull-distance The distance to trigger the pull refresh number | string 50
head-height Height of head number | string 50
loading-icon Loading icon string loading
pulling-txt Text to show when pulling string Pull to refresh...
loosing-txt Text to show when loosing string Loose to refresh...
loading-txt Text to show when loading string Loading...
complete-txt Text to show when complete string Refresh successfully
complete-duration Duration of text display when loading is complete (milliseconds),Load completion copy is not displayed when it is 0 number 0
duration Pull down animation duration number 0.3

Events

Event Description Arguments
change Emitted when draging or status changed {status:string,distance:number}
refresh Emitted after pulling refresh -

Slots

Name Description
pulling Content of head when at pulling
loosing Content of head when at loosing
loading Content of head when at loading
complete Content of head when at complete
default Default slot

더 알아보기 (Learn more)