parent
134e465dd0
commit
ecd46ba23d
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@bd/core",
|
||||
"version": "1.9.3",
|
||||
"version": "1.9.4",
|
||||
"type": "module",
|
||||
"description": "百搭UI组件库的核心",
|
||||
"main": "dist/index.js",
|
||||
|
|
|
@ -136,9 +136,7 @@ function getTemplateHtml(strings, type) {
|
|||
let htmlResult =
|
||||
html2 + (strings[len] || '<?>') + (type === SVG_RESULT ? '</svg>' : '')
|
||||
if (!Array.isArray(strings) || !strings.hasOwnProperty('raw')) {
|
||||
let message = 'invalid template strings array'
|
||||
|
||||
throw new Error(message)
|
||||
throw new Error('invalid html ast')
|
||||
}
|
||||
return [htmlResult, attrNames]
|
||||
}
|
||||
|
|
|
@ -337,7 +337,7 @@ export class Component extends HTMLElement {
|
|||
unbind(this, type, callback, options)
|
||||
}
|
||||
|
||||
$emit(type, data = {}) {
|
||||
return fire(this, type, data)
|
||||
$emit(type, data = {}, stop = false) {
|
||||
return fire(this, type, data, stop)
|
||||
}
|
||||
}
|
||||
|
|
10
src/utils.js
10
src/utils.js
|
@ -185,9 +185,15 @@ export function clearOutsideClick(fn = noop) {
|
|||
unbind(document, 'mousedown', fn)
|
||||
}
|
||||
|
||||
export function fire(el, name = 'click', data = {}) {
|
||||
/**
|
||||
* @param el <DOM> 节点
|
||||
* @param name <String> 自定义的事件名
|
||||
* @param data <Object> 要合并进event对象的参数
|
||||
* @param stop <Boolean> 是否禁止事件冒泡
|
||||
*/
|
||||
export function fire(el, name = 'click', data = {}, stop) {
|
||||
let ev = document.createEvent('Events')
|
||||
ev.initEvent(name, true, true)
|
||||
ev.initEvent(name, !stop, true)
|
||||
Object.assign(ev, data)
|
||||
el.dispatchEvent(ev)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue