通过您喜欢的包管理器将 @movk/core 添加到您的项目中。
pnpm add @movk/core
yarn add @movk/core
npm install @movk/core
@movk/core 是完全模块化的,您可以从库中直接导入需要使用的函数。例如,您可以在您的 Vue 组件或任何 JavaScript/TypeScript 文件中这样使用:
<script setup lang="ts">
import { debounce, upperFirst, useAppStorage } from '@movk/core'
import { ref } from 'vue'
// 使用工具函数
const text = ref('hello world')
const capitalizedText = upperFirst(text.value) // => 'Hello world'
console.log(capitalizedText)
const handleInput = debounce(() => {
console.log('Debounced function executed!')
}, 300)
// 使用组合式函数
const myState = useAppStorage('my-app-state', {
name: 'default',
count: 0
})
function increment() {
myState.value.count++
}
</script>
@movk/core 中的所有函数都是可摇树的 (tree-shakable)。这意味着在生产构建中,只有您实际导入和使用的代码才会被打包,从而确保您的应用程序保持轻量。