vue/no-expose-after-await 正确性
它的作用
禁止异步注册 expose。
为什么这很糟糕?
在 <script setup> 或 setup() 中,位于 await 表达式之后注册的 defineExpose 和 context.expose() 可能无法按预期工作, 因为它们是在组件实例完成设置之后才注册的。
示例
以下是此规则的错误代码示例:
vue
<script setup>
await doSomething();
defineExpose({
/* ... */
}); // 错误
</script>以下是此规则的正确代码示例:
vue
<script setup>
defineExpose({
/* ... */
}); // 正确
await doSomething();
</script>如何使用
To enable this rule using the config file or in the CLI, you can use:
json
{
"plugins": ["vue"],
"rules": {
"vue/no-expose-after-await": "error"
}
}ts
import { defineConfig } from "oxlint";
export default defineConfig({
plugins: ["vue"],
rules: {
"vue/no-expose-after-await": "error",
},
});bash
oxlint --deny vue/no-expose-after-await --vue-plugin版本
此规则在 v1.67.0 中添加。
