---
url: /docs/guide/usage/linter/rules/vue/no-deprecated-props-default-this.md
---

### 作用

禁止在 props 默认函数中使用已弃用的 `this` 访问（在 Vue.js 3.0.0+ 中）。

### 为什么这不好？

在 Vue.js 3.0.0+ 中，props 默认工厂函数不再能访问
`this`。它们在组件实例创建之前被调用，因此
`this` 是 `undefined`。工厂函数应改为依赖其第一个参数（即
由父组件传入的原始 props）。

### 示例

以下是此规则的**错误**代码示例：

```vue
<script>
export default {
  props: {
    a: String,
    b: {
      default() {
        return this.a;
      },
    },
  },
};
</script>
```

以下是此规则的**正确**代码示例：

```vue
<script>
export default {
  props: {
    a: String,
    b: {
      default(props) {
        return props.a;
      },
    },
  },
};
</script>
```

## 如何使用

## 版本

此规则于 v1.67.0 中添加。

## 参考资料
