# 解决编译器宏,例如defineProps和defineEmits生成no-undef警告

# ESLint <= v7.x

# 方式一



 
 




<script lang="ts" setup>
// https://staging-cn.vuejs.org/guide/components/events.html#usage-with-v-model
import { ref, watch } from "vue";
/* global defineProps, defineEmits */
const emits = defineEmits(["update:modelValue"]);
const props = defineProps(["modelValue"]);
<script>
1
2
3
4
5
6
7

# 方式二







 
 
 
 
 
 
 

module.exports = {
  root: true,
  env: {
    node: true
    // "vue/setup-compiler-macros": true
  },
  globals: {
    defineProps: "readonly",
    defineEmits: "readonly",
    defineExpose: "readonly",
    withDefaults: "readonly"
  }
}
1
2
3
4
5
6
7
8
9
10
11
12
13

# ESLint >= v8.x

.eslintrc.js 文件加入









 
 
 



module.exports = {
  "root": true,
  "extends": [
    "plugin:vue/vue3-essential",
    "eslint:recommended",
    "@vue/eslint-config-typescript/recommended",
    "@vue/eslint-config-prettier"
  ],
  "env": {
    "vue/setup-compiler-macros": true
  }
}

1
2
3
4
5
6
7
8
9
10
11
12
13