V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Anthony117
V2EX  ›  程序员

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

  •  
  •   Anthony117 · 2020-01-01 14:35:43 +08:00 · 2427 次点击
    这是一个创建于 1548 天前的主题,其中的信息可能已经有所发展或是发生改变。

    大家新年快乐!

    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

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

    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5410 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 09:09 · PVG 17:09 · LAX 02:09 · JFK 05:09
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.