fix: warning is not a valid value for v-model
in JetBrains IDE
#3029
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
这个 PR 做了什么? (简要描述所做更改)
相关问题
适用范围
intellij-community 2021 年起的所有版本。
我本地只验证了版本( IntelliJ IDEA 2021.2.3 到 IntelliJ IDEA 2023.3.2 )修复有效。
更早之前的版本有这个问题的话应该也适用。
修复说明
按照 WebStorm 相关代码的维护者所说,在 web-types.json 中应该使用属性名
modelValue
而非v-model
,这样做只能去掉警告但是会丢失代码提示(属性描述)。我结合了两种方式去修复,不需要等 IDE 修复:
在 web-types.json 中将
v-model
的定义拷贝一份为modelValue
同时兼容
v-model="value"
和:model-value="value"
两种用法。另外增加了
update:modelValue
事件( 支持被.md
文件中定义的内容覆盖 )。将
"type": "boolean"
改为"type": "boolean "
加空格 的目的是为了使
type
被识别为COMPLEX
类型而非BOOLEAN
类型 。这个写法看着是奇怪一点,但确实有效,比起 修改大小写 的方式( 比如修改为Boolean
)可以兼容旧的 IDE 。另外,目前 WebStorm 不支持
v-model
和modelValue
的类型校验,type
定义为任意复杂表达式都是一样的。具体分析见 JetBrains/web-types#79
测试步骤
新建项目安装依赖:
创建一个
Vue
文件:同时使用
"name": "v-model"
和"type": "boolean"
定义的组件会出现警告:相关组件:
nut-checkbox
nut-infinite-loading
nut-pull-refresh
nut-tour
修复之前:
修复之后:
这个 PR 是什么类型? (至少选择一个)
这个 PR 涉及以下平台:
这个 PR 是否已自测: