企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
[TOC] ***** ## 4 helper.js 编译助手 >[info] import ~~~ ;(导入)数组基础工具 import { isArray } from 'shared/util' ~~~ >[info] module ~~~ ;基础警告接口 export function baseWarn (msg) { console.error(`[Vue parser]: ${msg}`) } ;el添加prop export function addProp (el, name, value) { (el.props || (el.props = [])).push({ name, value }) } ;el添加attrs export function addAttr (el, name, value) { (el.attrs || (el.attrs = [])).push({ name, value }) } ;el添加StaticAttr export function addStaticAttr (el, name, value) { (el.staticAttrs || (el.staticAttrs = [])).push({ name, value }) } ;el添加指令 export function addDirective (el, name, value, arg, modifiers) { (el.directives || (el.directives = [])).push({ name, value, arg, modifiers }) } ;el添加style export function addStyleBinding (el, name, value) { const code = `"${name}":${value}` el.styleBinding = el.styleBinding ? el.styleBinding.replace(/}\s?$/, `,${code}}`) : `{${code}}` } ;el添加hook export function addHook (el, name, code) { const hooks = el.hooks || (el.hooks = {}) const hook = hooks[name] if (hook) { hook.push(code) } else { hooks[name] = [code] } } ;el添加事件handler export function addHandler (el, name, value, modifiers) { const events = el.events || (el.events = {}) // check capture modifier if (modifiers && modifiers.capture) { delete modifiers.capture name = '!' + name // mark the event as captured } const newHandler = { value, modifiers } const handlers = events[name] if (isArray(handlers)) { handlers.push(newHandler) } else if (handlers) { events[name] = [handlers, newHandler] } else { events[name] = newHandler } } ;获取绑定属性v-bind export function getBindingAttr (el, name, getStatic) { const staticValue = getStatic !== false && getAndRemoveAttr(el, name) return staticValue || staticValue === '' ? JSON.stringify(staticValue) : (getAndRemoveAttr(el, ':' + name) || getAndRemoveAttr(el, 'v-bind:' + name)) } ;获取帮删除绑定属性v-bind export function getAndRemoveAttr (el, name) { let val if ((val = el.attrsMap[name]) != null) { el.attrsMap[name] = null const list = el.attrsList for (let i = 0, l = list.length; i < l; i++) { if (list[i].name === name) { list.splice(i, 1) break } } } return val } ~~~ >[info] export ~~~ ;(导出)基础警告 export function baseWarn (msg) {} export function addProp (el, name, value) {} export function addAttr (el, name, value) {} export function addStaticAttr (el, name, value) {} export function addDirective (el, name, value, arg, modifiers) {} export function addStyleBinding (el, name, value) {} export function addHook (el, name, code) {} export function addHandler (el, name, value, modifiers) {} export function getBindingAttr (el, name, getStatic) {} export function getAndRemoveAttr (el, name) {} ;(导出)添加事件处理接口 export function addHandler (el, name, value, modifiers) {} ;(导出)获取绑定属性 export function getBindingAttr (el, name, getStatic) {} ;(导出)获取并删除绑定属性 export function getAndRemoveAttr (el, name) {} ~~~