[READ-ONLY] Mirror of https://github.com/sxzz/eslint-plugin-vuekit. Modern ESLint plugin for Vue 3 eslint-plugin-vuekit.sxzz.dev
eslint plugin vue
eslint-plugin-vuekit docs rules no-shared-component-data.md
1.9 kB · 87 lines
Markdown
at main


pageClass: rule-details sidebarDepth: 0 title: vue/no-shared-component-data description: enforce component's data property to be a function since: v3.8.0 #

vue/no-shared-component-data #

enforce component's data property to be a function

  • ⚙️ This rule is included in the following preset configs:
    • *.configs.essential
    • *.configs["strongly-recommended"]
    • *.configs.recommended
  • 🔧 The --fix option on the command line can automatically fix some of the problems reported by this rule.

When using the data property on a component (i.e. anywhere except on new Vue), the value must be a function that returns an object.

📖 Rule Details #

When the value of data is an object, it’s shared across all instances of a component.

<script>
/* ✓ GOOD */
Vue.component('some-comp', {
  data: function () {
    return {
      foo: 'bar'
    }
  }
})

export default {
  data() {
    return {
      foo: 'bar'
    }
  }
}
</script>
<script>
/* ✗ BAD */
Vue.component('some-comp', {
  data: {
    foo: 'bar'
  }
})

export default {
  data: {
    foo: 'bar'
  }
}
</script>

🔧 Options #

Nothing.

📚 Further Reading #

🚀 Version #

This rule was introduced in eslint-plugin-vue v3.8.0

🔍 Implementation #