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

@fim3/request

v1.0.1

Published

super request for vue

Downloads

7

Readme

安装

npm install @fc/request -S

基本使用


import Vue from 'Vue'

import {
  request,
  Cache
} from '@fc/request'

// 无参数初始化
Vue.protoType.$http = SuperRequest
// OR
// 携带参数初始化
Vue.protoType.$http = SuperRequest.create({
  baseUrl: '/g/fim3/xxx',
  debug: true,
  ...
})

API

| 参数 | 类型 | 默认值 | 说明 | | ----------- | ------- | ------ | ---------------- | | cache | boolean | false | 是否开启缓存 | | forceUpdate | boolean | false | 是否强制更新缓存 | | cancelTolen | Promise | / | 取消请求 | | dictionary | string | dictionary | 是否启动字典缓存 | | camelCase | boolean | true | 是否启动驼峰处理 | | encodeParams | boolean | false | 是否开启请求参数转义 | | targetEncode | Array | / | 是否指定特定的值进行转义 |

缓存


// 主动使用缓存
$http.get('/users', { cache: true }); 
// 自定义缓存
import { Cache } from 'super-request';
const cache1 = new Cache()
$http.get('/users', { cache: cache1 });
// 强制更新缓存
$http.get('/users', { cache: cache1, forceUpdate: true });


// post字典也可以进行缓存
$http.post('/name',{
  template_id: 1,
  dictionary: 9902
},{
  cache: true
})
.then(res=> {
  console.log('res',res);
})
// 是否启用驼峰处理
$http.post('/name',{
  template_id: 1,
  dictionary: 9902
},{
  camelCase: false
})
.then(res=> {
  // 返回的数据会保留a_b的格式
  console.log('res',res);
})

// 开启转义
$http.post('/name',{
  template_id: 1,
  dictionary: 9902
},{
  encodeParams: true
})
.then(res=> {
  // script和sql注入会被转义
  console.log('res',res);
})
// 开启转义后会有sql注入和script注入自动转义
// sql注入正则
private regSql = /select|update|delete|truncate|join|union|exec|insert|drop|count|'|"|=|;|>|</i
// 非法<script></script>标签
private regScript = /<script[^>]*>[\s\S]*?<\/[^>]*script>/gi

//e.g以下输入开启 encodeParams: true后会被自动转义
<script><script>
select * from
insert
// 关键词命中后会自动encode

// 开启特定值转义
$http.post('/name',{
  dictionary: "!@#$%^&*",
  val: {
    a: '<script>',
    b: 'query'
  }
},{
  encodeParams: true,
  targetEncode: ['dictionary', 'a']
})
.then(res=> {
  // dictionary和 a 会被转义
  console.log('res',res);
})