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

storegather

v1.0.0

Published

将所有的vuex所需要的集合到一起,由每个页面进行引入,方便维护自身页面的api

Downloads

6

Readme

storegather 将 store 分散存放在每个页面中,如 在src下新建pages目录 pages/home

home.vue 页面 存放在 home 目录下

state.js

export default {
      count:0 , // 页面计数
      goods:[
         {'id':1,'name':'产品1','type':'hot'},
         {'id':2,'name':'产品2','type':'put'},
         {'id':3,'name':'产品3','type':'hot'},
         {'id':4,'name':'产品4','type':'hot'},
         {'id':5,'name':'产品5','type':'put'},
         {'id':6,'name':'产品6','type':'hot'},
      ]
}

mutations.js

export default {
      add(state){
         state.count +=1;
      },
      minus(state){
         state.count -=1;
      },
      pushgoods(state,newgoods){
          newgoods.forEach((item)=>{
             state.goods.push(newgoods[i]);
          })
      }
}

getters.js

export default {
      hotgoods(state){ // 热销产品
         return state.goods.filter(good => good.type === 'hot')
      }
}

actions.js

export default {
      async getInfo({commit},arg){
         let {data} = await axios.get('http://www.xxx.com/getgoods?type=json');
         commit('pushgoods',data);
      }
}

按照以上的设计规则,就是将store分散到每个页面的目录下,思路更清晰,每个页面调用的方法,挂载的全局变量,回到当前页面进行修改

分散后,就要分别进行合并,有两个思路

1)在当前页面新建一个集合文件 (gather.js) 推荐

import state from './state.js'
import mutations from './mutations.js'
import getters from './getters.js'
import actions from './actions.js'
export default {
   state,
   mutations,
   getters,
   actions
}

2)分别将每个页面引入到main.js 中

例子:

import Vue from 'vue'
import App from './App'
import router from './router'

// 分散集合store模块
import {Gather,store} from 'storegather';

*********方法1*************
import homeGather from './pages/home/gather.js';
// ... 不停地添加页面进来...
Gather.setState(homeGather.state,...) // xxx1,xxx2,xxx3 如此类推
Gather.setMutations(homeGather.mutations,...)
Gather.setGetters(homeGather.getters,...)
Gather.setActions(homeGather.actions,...)
**********************

*********方法2*************
import homeState from './pages/home/state.js';
import homeMutations from './pages/home/mutations.js';
import homeGetters from './pages/home/getters.js';
import homeActions from './pages/home/actions.js';
// ... 不停地添加页面进来...
Gather.setState(homeState,...) // xxx1,xxx2,xxx3 如此类推
Gather.setMutations(homeMutations,...)
Gather.setGetters(homeGetters,...)
Gather.setActions(homeActions,...)
**********************

new Vue({
  el: '#app',
  router,
  store,
  components: { App },
  template: '<App/>'
})

安装

npm install storegather --save

// 需要配合 vue vuex npm install vue vuex --save

在main.js中使用

// Gather 集合好,就会返回一个已经集合好的store模块 并且已经new Vuex.Store({已经集合好了}) import {Gather,store} from 'storegather'

Gather.setState(homeState,...) // xxx1,xxx2,xxx3 如此类推 Gather.setMutations(homeMutations,...) Gather.setGetters(homeGetters,...) Gather.setActions(homeActions,...)

new Vue({ el: '#app', router, store, components: { App }, template: '' })