Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-app
提交
a6834452
U
uni-app
项目概览
DCloud
/
uni-app
3 个月 前同步成功
通知
720
Star
38705
Fork
3642
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
7
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
7
Issue
7
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
a6834452
编写于
4月 21, 2022
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(nvue): v-model with input,textarea (question/143547)
上级
66fc6f50
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
31 addition
and
6 deletion
+31
-6
packages/uni-app-vite/__tests__/nvue/__snapshots__/compiler.spec.ts.snap
...p-vite/__tests__/nvue/__snapshots__/compiler.spec.ts.snap
+4
-4
packages/uni-app-vite/src/nvue/plugin/transforms/vModel.ts
packages/uni-app-vite/src/nvue/plugin/transforms/vModel.ts
+27
-2
未找到文件。
packages/uni-app-vite/__tests__/nvue/__snapshots__/compiler.spec.ts.snap
浏览文件 @
a6834452
...
...
@@ -8,8 +8,8 @@ const _hoisted_1 = [\\"modelValue\\"]
export function render(_ctx, _cache) {
return (_openBlock(), _createElementBlock(\\"u-input\\", {
modelValue: _ctx.text,
\\"onUpdate:modelValue\\": _cache[0] || (_cache[0] = $event => ((_ctx.text) = $event
))
}, null,
8 /* PROP
S */, _hoisted_1))
onInput: _cache[0] || (_cache[0] = $event => ((_ctx.text) = $event.detail.value
))
}, null,
40 /* PROPS, HYDRATE_EVENT
S */, _hoisted_1))
}"
`;
...
...
@@ -45,8 +45,8 @@ const _hoisted_1 = [\\"modelValue\\"]
export function render(_ctx, _cache) {
return (_openBlock(), _createElementBlock(\\"u-textarea\\", {
modelValue: _ctx.text,
\\"onUpdate:modelValue\\": _cache[0] || (_cache[0] = $event => ((_ctx.text) = $event
))
}, null,
8 /* PROP
S */, _hoisted_1))
onInput: _cache[0] || (_cache[0] = $event => ((_ctx.text) = $event.detail.value
))
}, null,
40 /* PROPS, HYDRATE_EVENT
S */, _hoisted_1))
}"
`;
...
...
packages/uni-app-vite/src/nvue/plugin/transforms/vModel.ts
浏览文件 @
a6834452
import
{
transformModel
as
baseTransform
,
DirectiveTransform
,
isStaticExp
,
NodeTypes
,
}
from
'
@vue/compiler-core
'
// 所有的 v-model 均走自定义组件的实现逻辑,包括 input,textarea
const
tags
=
[
'
u-input
'
,
'
u-textarea
'
]
export
const
transformModel
:
DirectiveTransform
=
(
dir
,
node
,
context
)
=>
{
return
baseTransform
(
dir
,
node
,
context
)
const
result
=
baseTransform
(
dir
,
node
,
context
)
// 将 u-input,u-textarea 的 onUpdate:modelValue 事件转换为 onInput
if
(
tags
.
includes
(
node
.
tag
)
&&
result
.
props
.
length
>=
2
)
{
const
key
=
result
.
props
[
1
].
key
let
value
=
result
.
props
[
1
].
value
if
(
value
.
type
===
NodeTypes
.
JS_CACHE_EXPRESSION
)
{
value
=
value
.
value
}
if
(
isStaticExp
(
key
)
&&
key
.
content
===
'
onUpdate:modelValue
'
&&
value
.
type
===
NodeTypes
.
COMPOUND_EXPRESSION
)
{
key
.
content
=
'
onInput
'
// 替换 $event 为 $event.detail.value
value
.
children
=
value
.
children
.
map
((
child
)
=>
{
if
(
typeof
child
===
'
string
'
)
{
return
child
.
replace
(
/=
\s\$
event/g
,
`= $event.detail.value`
)
}
return
child
})
}
}
return
result
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录