2.0.3 • Published 9 years ago
salt-fetch v2.0.3
salt.fetch
独立的ajax/jsonp模块。
特别说明
salt.fetch就是 nattyFetch 和 nattyStorage 的引用合集,看源代码便知。
为什么这么做?为了给salt的使用者提供一致的开发体验,故将nattyFetch工具以fetch属性的方式集成在salt命名空间下。
安装
通过npm下载代码,目前最新版本为2.0.0
npm install salt-fetch --save插入代码
<script src="path/to/node_modules/salt-fetch/dist/salt-fetch.js"></script>文档
salt.fetch的特点和文档,直接见 nattyFetch 的文档即可。原文档中使用nattyFetch的地方,都可以直接使用salt.fetch替换,一模一样,如:
原nattyFetch文档:
const context = nattyFetch.context({
urlPrefix: '//example.com/api/'
});
context.create({
getList: {
url: 'getList.do',
plugins: [
nattyFetch.plugin.soon
]
}
});
module.exports = context.api;使用salt.fetch后:
const context = salt.fetch.context({ // 用`salt.fetch`替换`nattyFetch`
urlPrefix: '//example.com/api/'
});
context.create({
getList: {
url: 'getList.do',
plugins: [
salt.fetch.plugin.soon // 用`salt.fetch`替换`nattyFetch`
]
}
});
module.exports = context.api;
salt.fetch和nattyFetch的不同之处:
salt.fetch只有移动端版本。salt-fetch.js文件内置了natty-fetch.js和natty-storage.js两个文件的内容。而natty-fetch.js没有内置natty-storage.js文件的内容。