Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

请考虑对options的处理切入点。 #20

Open
xuguogang opened this issue Jul 18, 2016 · 2 comments
Open

请考虑对options的处理切入点。 #20

xuguogang opened this issue Jul 18, 2016 · 2 comments
Milestone

Comments

@xuguogang
Copy link

如果在context.create({}),这里的选项,没有办法进行后继的一些处理,比如基于某些原因,项目中途使用此组件或者基于标准写法定义选项,后续是没有办法进行转换的。

dataContext.create({
getInitData: {
method: "GET",
url: "invoice/getInitData",
cache: "default"
})

比如 cache: "default" 是按fetch标准写法,要转换成你的storage,是无法实现的。

我加了一个事件,可以处理了,还有根据method == "POST"就可以全局作一些处理,这都是很常见的作法,
context.on("processOptions", function (config) {
if (config.method == "POST") {
config.header = Object.assign({}, config.header, { "Content-Type": "text/json" });
}

if (config.cache === "default") {
    config.storage = { type: 'localStorage', key: config.url, tag: 'v1.0' };
}

});

还有一个问题,目前导致我不能继续使用这个组件了,

在sendAjax 中POST方法下处理主体数据,你在内部序列化时进行了 params 化,但是并不是所有数据都是这种处理方法,外部无法进行处理。比如,我项目的提交数据格式必须是json。像zepto,jquery都有这方法的机制,用processData标记是否需要内部进行处理。

@jias
Copy link
Member

jias commented Jul 18, 2016

第一个问题:

请求在发送之前会调用willFetch回调,接收两个参数varsconfigvars是每次请求的动态数据,config是内部process后的options的结果。可以通过在这个回调里修改config

第二个问题:

你指出的应该是参数命名问题,你建议使用cache,是这样理解吗?

第三个问题:

好问题!希望传JSON字符串,你希望具体怎么写?我看看能不能提供支持。

@sparkleDai
Copy link

碰到同样的问题,什么时候可以提供直接传递json的功能?不然只能回到zepto了

@jias jias mentioned this issue Sep 7, 2016
6 tasks
@jias jias added this to the 3.0 milestone Sep 7, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants