0.5.1 • Published 4 years ago
vx-hook v0.5.1
vx-hook
以umi-hooks为模板的 vue-hook 实现
Install
yarn add vx-hook
or
npm i --save vx-hook
当前vue 版本为 3.0.0-beta.1
Usage
组件内使用
<template>
<div class="home">
<div>
<Card style='margin: 20% auto; width: 600px' title=''>
<h2> {{ state.name }} </h2>
<div> default: {{ state.age }} </div>
<div> throttle: {{ info }} </div>
<Button @click='add' > add </Button>
</Card>
</div>
</div>
</template>
<script>
import { reactive } from 'vue'
import { useThrottle } from 'vx-hook'
export default {
setup(){
const state = reactive({name: 'jeck', age: 23})
const add = () => state.age += 1
const [ info ] = useThrottle(() => state.age, 1000) // 防抖hook
return {
add,
state,
info,
}
}
}
</script>