DefineProps and defineEmits apis must be used to declare props and emits in

<script setup>
const props = defineProps({
  foo: String
})

const emit = defineEmits(['change'.'delete'])
// setup code
</script>

Copy the code

From official documentation: Single-file components

  • defineProps 和 defineEmitsAre only in<script setup>In order to useThe compiler macros. They do not need to be imported and will follow<script setup>The processing is compiled together.
  • definePropsReceive andpropsoptionsThe same value,defineEmitsAlso to receiveemitsoptionsSame value.
  • defineProps 和 defineEmitsAfter the option is passed in, appropriate type inference is provided.
  • The incoming todefineProps 和 defineEmitsThe options are promoted from Setup to the scope of the module. Therefore, the passed option cannot refer to local variables declared in the setup scope. Doing so will cause a compilation error. However, itcanReference the imported bindings because they are also in the scope of the module.

I thought you could just use it? Why is it wrong?

 error  'defineProps' is not defined  no-undef
Copy the code

To solve

In eslintrc.js configuration:

module.exports = {
  env: {
    'vue/setup-compiler-macros': true}}Copy the code

User Guide | eslint-plugin-vue (vuejs.org)