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

yxl-ajax

v1.0.7

Published

同步和异步Ajax工具

Downloads

22

Readme

npm 版本 npm 许可 npm 每月下载数 npm 大小

特性

  • 轻巧 大小为2KB
  • 支持同步调用
  • 异步调用为链式语法
  • 使用ES6模块语法

安装

使用npm安装:

npm install yxl-ajax  --save

或直接导入:

<script src='yxl.ajax.min.js' type='text/javascript'>
</script>

引入

Vue实例中

在入口页面 main.js 作如下配置:

import YxlAjax from 'yxl-ajax'
Vue.use(YxlAjax,'基准网址')

注意:

  • 必须放在new Vue语句前
  • 基准网址可以不提供
  • 要么基准网址以一个斜杆结尾,要么方法网址以一个斜杆开始 然后在实例方法中
  • 使用this.$ajaxSync调用同步方法
  • 使用this.$ajaxAsync调用异步方法

JS脚本中

在页首导入模块和生成对象:

import YxlAjax from 'yxl-ajax'
let $ajaxSync=Yxl.ajaxSync('基准网址'))//同步
let $ajaxAsync=Yxl.ajaxAsync('基准网址'))//异步

注意:

  • 基准网址可以不提供
  • 要么基准网址以一个斜杆结尾,要么方法网址以一个斜杆开始 然后在接着的脚步中
  • 使用$ajaxSync调用同步方法
  • 使用$ajaxAsync调用异步方法

同步调用

  • get和delete方法的参数为相对网址
  • post、put和patch方法的参数包括相对地址和要发送的数据
  • 调用成功时,返回值为服务器返回的数据
  • 调用失败时,将抛出信息为错误状态码的异常
  • get 方法
    let 返回数据=this.$ajaxSync.get('相对网址')
    • post 方法
    let 返回数据=this.$ajaxSync.post('相对网址',数据对象)
    • put 方法
    let 返回数据=this.$ajaxSync.put('相对网址',数据对象)
    • delete 方法
    let 返回数据=this.$ajaxSync.delete('相对网址')
    • patch 方法
    let 返回数据=this.$ajaxSync.delete('相对网址',数据对象)

异步调用

  • get、post、put、delete和patch方法的参数为相对网址
  • 在ok方法中设置调用成功的回调函数,回调函数的参数为服务器返回数据,可不设置
  • 在error方法中设置调用失败的回调函数,回调函数的参数依此为错误状态码,错误状态文本和服务器返回数据,可不设置
  • 最后调用Run方法提交要传给服务端的数据
    this.$ajaxAsync.get('相对网址').ok(成功回调函数).error(失败回调函数).run()
    • post 方法
    this.$ajaxAsync.post('相对网址').ok(成功回调函数).error(失败回调函数).run(数据对象))
    • put 方法
    this.$ajaxAsync.put('相对网址').ok(成功回调函数).error(失败回调函数).run(数据对象))
    • delete 方法
    this.$ajaxAsync.delete('相对网址').ok(成功回调函数).error(失败回调函数).run())
    • patch 方法
    this.$ajaxAsync.patch('相对网址').ok(成功回调函数).error(失败回调函数).run(数据对象))

    备注

如发现错误或提建议,请提交 issue 或发送邮件到
##[email protected] 请关注公众号了解更多信息 NET全栈程序员