npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vcomposition2

v1.1.8

Published

在vue2上使用组合API的玩具

Downloads

7

Readme

vue2 组合APi使用

兴起随意写,还是有蛮多地方没考虑到的

有愿意一起讨论学习的可以+我哈

vomposition2其实是这个的第一个版本但是名字取错了,哈哈

不过在多人协作上不能够很好的知道是否有覆盖其挂载的方法。

推荐在不同入口定义的方法,能够加上namespace前缀来命名。

api

Vcomposition2,V2Init

用来包裹传递对象,会在上面挂载一个root和cd属性

cd用来模拟computed

其余属性都将挂载到root上

Vcomposition2 >> new Vcomposition2(vueInstance);

ref ---> v2.ref("value", "张三");

reactive ---> v2.reactive({age: 24,name:'xxn'});

events

示例

//生命周期可以嵌套使用
onCreate(()=>{ 
 
 const v2 =   new  Vcomposition2(this);
 const {root} = v2;
 
 /**
  * ref和reactive通过$set实现
  * 不过$set设置完会通知父属性的dep通知watch更新
  * 这里暂时没深入考虑
 */
 const name = v2.ref("name",18);

 //等于正常挂载在methods上的方法
 const setName = (value)=> {
     root.name = value;
 }

 //onUnMounted and onDestroyed 不会挂载返回的方法
 return {
    setName
 }
})

onCreate ---> created

onMounted(使用方式同onCreate) --> mounted

onUnMounted --> beforeDestroy

onDestroyed --> destroyed

onWatch ---> vue.$watch

onComputed

//将会挂载到实例上的cd属性
v2.onComputed("nameSuffix", () => {
    return root.value + "谢谢你";
});

use 可以传入Array的方法泛型 再或者传入单个Funtion 或者链式使用

//类似useHook使用

/**
 * this指向的是vue实例
 * @param {Vcomposition2} ctx Vcomposition2的实例
 * @param {object} root ctx下的root
*/
function useInput(ctx,root){

    ctx.ref("inputValue","")

    const setInput = (value) =>{
        
        root.inputValue  = value;
     //or this.root.inputValue = value
    }

    return {
        setInput
    }

}

onCreate(()=>{ 
 
 const v2 =   new  Vcomposition2(this);
 
 v2.use(useInput);//将代码更加细化
})