Merge pull request #460 from mingkang1993/patch-17

事件模型:找到dom属性 保持跟微信api 一样 放入detail
This commit is contained in:
当耐特 2019-10-13 22:30:09 -05:00 committed by GitHub
commit 925fe64b41
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 27 additions and 2 deletions

View File

@ -30,6 +30,28 @@ export function fixProps(properties){
return props
}
// 找到dom属性 保持跟微信api 一样 放入detail
function findDomData(dom) {
const resData = {};
if(!dom) {
return resData
}
const attr = dom.attributes;
for(let key of Object.keys(attr)){
let item = attr[key];
let localName = item.localName.replace(/\s+/g, "");
if(localName.match(/^data-/)){
resData[localName.replace('data-', '')] = item.value;
}
}
return resData;
}
// 代理input
export function helpInputEvent(fn, e){
if(!e.detail){
@ -40,8 +62,11 @@ export function helpInputEvent(fn, e){
});
}
Object.defineProperty(e.detail,'value',{
value: e.target.value,
Object.defineProperty(e,'detail',{
value: {
value: e.target.value,
...findDomData(e.target)
},
writable: false,
configurable : true
});