智能照明系统APP-本地串口
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
LightingSystemApp-serial/.svn/pristine/de/deecd7228653513cb1494d553ea...

34 lines
883 B

3 years ago
/* @flow */
import { addHandler, addAttr } from 'compiler/helpers'
import { genComponentModel, genAssignmentCode } from 'compiler/directives/model'
export default function model (
el: ASTElement,
dir: ASTDirective
): ?boolean {
if (el.tag === 'input' || el.tag === 'textarea') {
genDefaultModel(el, dir.value, dir.modifiers)
} else {
genComponentModel(el, dir.value, dir.modifiers)
}
}
function genDefaultModel (
el: ASTElement,
value: string,
modifiers: ?ASTModifiers
): ?boolean {
const { lazy, trim, number } = modifiers || {}
const event = lazy ? 'change' : 'input'
let valueExpression = `$event.target.attr.value${trim ? '.trim()' : ''}`
if (number) {
valueExpression = `_n(${valueExpression})`
}
const code = genAssignmentCode(value, valueExpression)
addAttr(el, 'value', `(${value})`)
addHandler(el, event, code, null, true)
}