优化 `lay.options()` 方法,以提供更直观的异常提示

pull/1167/head
贤心 2022-11-14 00:47:55 +08:00
parent 441f3dda48
commit d9cfe611ca
1 changed files with 6 additions and 2 deletions

View File

@ -208,11 +208,15 @@
var othis = lay(elem);
var attrName = opts.attr || 'lay-options';
var attrValue = othis.attr(attrName);
try {
return new Function('return '+ (othis.attr(attrName) || '{}'))();
return new Function('return '+ (attrValue || '{}'))();
} catch(ev) {
hint.error(opts.errorText || 'parseerror: '+ ev, 'error');
layui.hint().error(opts.errorText || [
attrName + '="'+ attrValue + '"',
'\n parseerror: '+ ev
].join('\n'), 'error');
return {};
}
};