【问题标题】:Vue jsx, h in render function is defined but never usedVue jsx,渲染函数中的h已定义但从未使用过
【发布时间】:2020-03-02 21:38:42
【问题描述】:

我正在使用 vue jsx,问题是 eslint 给了我这个关于 h 已定义但未使用的错误。所有的设置和安装都是默认的 vue 配置。

除了错误之外,代码都可以工作。

这是我的代码

//HelloWorld.vue
<script>
export default {
  name: "HelloWorld",
  render: function(h) {
    return (<h1>Hello World</h1>);
  }
};
</script>
//App.vue
<template>
  <HelloWorld />
</template>

<script>
import HelloWorld from "./components/HelloWorld.vue";

export default {
  name: "App",
  components: {
    HelloWorld
  }
};
</script>

我该如何解决这个问题? 注意:如果我只是删除它抛出的 h:ReferenceError: h is not defined

【问题讨论】:

    标签: vue.js jsx


    【解决方案1】:

    您可以尝试明确跳过导致问题的行

    <script>
    export default {
      name: "HelloWorld",
      // eslint-disable-next-line no-unused-vars
      render: function(h) {
        return (<h1>Hello World</h1>);
      }
    };
    </script>
    

    或者你可以通过删除h来修复它

    <script>
    export default {
      name: "HelloWorld",
      render: function() { // <=== here
        return (<h1>Hello World</h1>);
      }
    };
    </script>
    

    【讨论】:

    • 那个不行,会不会是我的vue版本过时了?
    • 奇怪,也许是 jsx 造成的,但我不知道为什么。无论如何,添加了另一个显式跳过一行的选项。
    • 另外,注意这里的讨论,可能是相关的(eslint-plugin-vue)github.com/vuejs/eslint-plugin-vue/issues/…
    猜你喜欢
    • 1970-01-01
    • 2020-04-01
    • 2020-12-07
    • 1970-01-01
    • 2020-10-31
    • 2020-07-28
    • 2018-07-05
    • 1970-01-01
    • 2021-04-19
    相关资源
    最近更新 更多