jdf2e / nutui

京东风格的移动端 Vue 组件库,支持多端小程序(A Vue.js UI Toolkit for Mobile Web)
https://nutui.jd.com
MIT License
6.01k stars 814 forks source link

fix: warning `is not a valid value for v-model` in JetBrains IDE #3029

Closed anyesu closed 2 months ago

anyesu commented 3 months ago

这个 PR 做了什么? (简要描述所做更改)

相关问题

适用范围

intellij-community 2021 年起的所有版本。

Version 2.0 of the format

Starting with version 2021.3.1 of WebStorm (and other JetBrains IDEs), a full support for the new Web-Types format is supported (the new format has been partially supported since 2021.2).

我本地只验证了版本( IntelliJ IDEA 2021.2.3IntelliJ IDEA 2023.3.2 )修复有效。

更早之前的版本有这个问题的话应该也适用。

修复说明

按照 WebStorm 相关代码的维护者所说,在 web-types.json 中应该使用属性名 modelValue 而非 v-model ,这样做只能去掉警告但是会丢失代码提示(属性描述)。

我结合了两种方式去修复,不需要等 IDE 修复:

具体分析见 https://github.com/JetBrains/web-types/issues/79

测试步骤

  1. 新建项目安装依赖:

    npm i vue @nutui/nutui
  2. 创建一个 Vue 文件:

    <template>
     <div>
       <nut-checkbox v-model="value" />
       <nut-infinite-loading v-model="value" />
       <nut-pull-refresh v-model="value" />
       <nut-tour v-model="value" :steps="steps" />
    
       <nut-checkbox :model-value="value" @update:model-value="value = $event" />
       <nut-infinite-loading :model-value="value" @update:model-value="value = $event" />
       <nut-pull-refresh :model-value="value" @update:model-value="value = $event" />
       <nut-tour :steps="steps" :modelValue="value" @update:modelValue="value = $event" />
     </div>
    </template>
    
    <script setup lang="ts">
    import { ref } from "vue";
    
    const value = ref(false);
    
    const steps = ref([
     {
       content: "京东风格的轻量级移动端组件库",
       target: "tour1",
     },
    ]);
    </script>
  3. 同时使用 "name": "v-model""type": "boolean" 定义的组件会出现警告:

    value is not a valid value for v-model

    相关组件:

    • nut-checkbox
    • nut-infinite-loading
    • nut-pull-refresh
    • nut-tour

修复之前:

修复前

修复之后:

修复后

这个 PR 是什么类型? (至少选择一个)

这个 PR 涉及以下平台:

这个 PR 是否已自测:

codecov[bot] commented 3 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 84.01%. Comparing base (f83471e) to head (8af6e23). Report is 1 commits behind head on v4.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## v4 #3029 +/- ## ======================================= Coverage 84.00% 84.01% ======================================= Files 218 218 Lines 23308 23308 Branches 2517 2518 +1 ======================================= + Hits 19581 19582 +1 + Misses 3709 3708 -1 Partials 18 18 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.