渲染函数中的Vue jsx,h已定义,但从未使用过



Am正在使用vue jsx,问题是esint给了我这个关于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没有定义

您可以尝试显式跳过导致问题的行

<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>

最新更新