• 请不要在回答技术问题时复制粘贴 AI 生成的内容
Anthony117
V2EX  ›  程序员

VueUse: Vue Composition API 常用工具集,同时支持 Vue 2.x 和 3.x

  •  
  •   Anthony117 · Jan 1, 2020 · 3451 views
    This topic created in 2348 days ago, the information mentioned may be changed or developed.

    大家新年快乐!

    https://github.com/antfu/vueuse

    VueUse: 一个 Vue Composition API 的常用工具集,同时支持 Vue 2.x 和 3.x

    这个项目很大程度启发于 react-use。Vue Compostion API 支持了更好的逻辑分离,让这些常用的工具可以被复用,能够让你快速地建构丰富的应用。

    以下是一些简单的例子

    import { useLocalStorage } from '@vueuse/core'
    
    export default new Vue({
      setup() {
        // 对 state 的改动都会自动存入 localStorage
        const state = useLocalStorage('storage-key', { name: 'john', age: 25 })
        return { state }
      }
    })
    
    import { usePreferredDark } from '@vueuse/core'
    
    export default new Vue({
      setup() {
        // 获取系统是否为深色模式
        const isDark = usePreferredDark()
        return { isDark }
      }
    })
    

    更多的例子和文档请查看: https://github.com/antfu/vueuse

    如果有任何想法或建议欢迎在下面留言~谢谢!

    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2825 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 04:27 · PVG 12:27 · LAX 21:27 · JFK 00:27
    ♥ Do have faith in what you're doing.