Movatterモバイル変換


[0]ホーム

URL:


Read-only property of Vue should not be assigned

  • VUE_ASSIGN_TO_READONLY_PROPERTY
  • Error
  • Medium
  • vue

This rule applies when a value is assigned to the read-only properties of Vue.

The read-only properties of Vue are as follows:

  1. $data
  2. $props
  3. $el
  4. $options
  5. $parent
  6. $root
  7. $children
  8. $slots
  9. $scopedSlots
  10. $refs
  11. $isServer
  12. $attrs
  13. $listeners
  14. Vue.config (Vue 2.x) orapp.config (Vue 3.x)

Assignment to the above properties will be ignored or may cause an unintended behavior. Also, Vue outputs a warning message.

Noncompliant Code ExampleCompliant Code Example
1<script>1<script>
2export default {2export default {
3 data() {3 data() {
4 return { msg: '' };4 return { msg: '' };
5 },5 },
6 mounted() {6 mounted() {
7 this.$data = { msg: 'hi' }; // VUE_ASSIGN_TO_READONLY_PROPERTY alarm because 'this.$data' is read-only.7 this.msg = 'hi'; // Use nested data properties instead.
8 }8 }
9}9}
10</script>10</script>

Noncompliant Code Example

View with compliant examples side by side
<script>export default {  data() {    return { msg: '' };  },  mounted() {    this.$data = { msg: 'hi' }; // VUE_ASSIGN_TO_READONLY_PROPERTY alarm because 'this.$data' is read-only.  }}</script>

Compliant Code Example

View with noncompliant examples side by side
<script>export default {  data() {    return { msg: '' };  },  mounted() {    this.msg = 'hi'; // Use nested data properties instead.  }}</script>

Version

This rule was introduced in DeepScan 1.16.0-beta.

See

  • Vue instance properties

  • Vue.config API

  • [Vue warn]: Avoid replacing instance root $data. Use nested data properties instead.

  • [Vue warn]: $props is readonly.

  • [Vue warn]: Error in mounted hook:TypeError: Cannot set property $isServer of #<Vue> which has only a getter

  • [Vue warn]: $attrs is readonly.

  • [Vue warn]: $listeners is readonly.

  • [Vue warn]: Do not replace the Vue.config object, set individual fields instead.

Was this documentation helpful?

Last updated on April 29, 2025

[8]ページ先頭

©2009-2025 Movatter.jp