提交 56305f54 编写于 作者: fxy060608's avatar fxy060608

fix(app): v-model (#3107)

上级 d907274f
......@@ -232,3 +232,15 @@ export function setHolderText(holder: Element, clazz: string, text: string) {
// 添加文本节点
holder.appendChild(document.createTextNode(text))
}
const vModelNames = ['value', 'modelValue']
export function initVModel(props: Record<string, any>) {
vModelNames.forEach((name) => {
if (hasOwn(props, name)) {
const event = 'onUpdate:' + name
if (!hasOwn(props, event)) {
props[event] = (v: string) => (props[name] = v)
}
}
})
}
import '@dcloudio/uni-components/style/input.css'
import { Input } from '@dcloudio/uni-components'
import { UniNodeJSON } from '@dcloudio/uni-shared'
import { UniComponent } from './UniComponent'
import { initVModel, UniComponent } from './UniComponent'
export class UniInput extends UniComponent {
constructor(
......@@ -12,4 +12,8 @@ export class UniInput extends UniComponent {
) {
super(id, 'uni-input', Input, parentNodeId, refNodeId, nodeJson)
}
init(nodeJson: Partial<UniNodeJSON>): void {
super.init(nodeJson)
initVModel(this.$props)
}
}
import '@dcloudio/uni-components/style/textarea.css'
import { Textarea } from '@dcloudio/uni-components'
import { UniNodeJSON } from '@dcloudio/uni-shared'
import { UniComponent } from './UniComponent'
import { initVModel, UniComponent } from './UniComponent'
export class UniTextarea extends UniComponent {
constructor(
......@@ -12,4 +12,9 @@ export class UniTextarea extends UniComponent {
) {
super(id, 'uni-textarea', Textarea, parentNodeId, refNodeId, nodeJson)
}
init(nodeJson: Partial<UniNodeJSON>): void {
super.init(nodeJson)
initVModel(this.$props)
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册