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

vuex-axios-sync

v11.0.0

Published

在vuex中注册一个模块来同步axios请求的状态

Downloads

6

Readme

vuex-axios-sync

在vuex中注册一个模块来同步axios请求的状态

使用

npm install vuex-axios-sync -S

or

yarn add vuex-axios-sync -S

main.js

import syncVuexAxios from 'vuex-axios-sync'
import request from './utils/request' // axios instance
import store from  './store/' // vuex store instance

syncVuexAxios(store,request)

组件中使用

<script>
export default = {
  computed: {
    ...mapState('loading', ['global', 'effects'])
  }
}

</script>

支持自定义模块的名称(模块默认名称:loading)

syncVuexAxios(store, router, { moduleName: 'customName' } )

支持最小请求时间(默认为0),单位毫秒

syncVuexAxios(store,router, { minRequestTime: 0 } )

如何工作

  • 在vuex中添加 loading 模块,初始state:
state = {
  global: false,
  effects: {}
}
  • 当发起一个网络请求时,在state.effects对象中添加一个属性(属性名:'${method}${url}')

创建axios实例

import axios from 'axios'

const request = axios.create({baseURL: 'http://request.com'})

... // 设置拦截器、错误处理等操作

export default request

发起请求

import request from 'utils/request'

const getGoodsListURL = `/goodsList`
const getGoodsListKey = `get${getGoodsListURL}` // 在effects对象中的key
request({url:getGoodsListURL,method: 'GET'})

此时state:

state = {
  global: true,
  effects: {
    "get/goodsList": true
  }
}
  • 请求完成时的state
state = {
  global: false,
  effects: {
    "get/goodsList": false
  }
}

注意

  • axios会自动将HTTP请求方法转为小写(GET -> get)
request({url:getGoodsListURL,method: 'GET'}) // effects中的属性名为:'`get${getGoodsListURL}`'
  • 如果同时发起多个请求,所有请求都完成state.global = false,否则state.global = true