Home  >  Article  >  Web Front-end  >  What to do if vue.set() error occurs

What to do if vue.set() error occurs

coldplay.xixi
coldplay.xixiOriginal
2020-11-27 11:17:572178browse

The solution to vue.set() error: use [Vue.set()] to add attributes to the object in data, the code is [export default {data() {return {info: {width: '100'}}}].

What to do if vue.set() error occurs

The operating environment of this tutorial: Windows 7 system, Vue version 2.9.6, Dell G3 computer.

Solution to vue.set() error:

Use Vue.set()Add attributes directly to data

  export default {
    data() {
      return {
        width: '100'
      }
    },
    methods: {
        scrollFn(e) {
         Vue.set(this.data, 'height', 0)
        }
      }
    }
  }

Error report:

What to do if vue.set() error occurs

Analysis: You cannot add attributes to direct data. You can add attributes to objects in data, for example:

  export default {
    data() {
      return {
    info: {
      width: '100'
    }
      }
    },
    methods: {
        scrollFn(e) {
         Vue.set(this.info, 'height', 0)
        }
      }
    }
  }

Expand :

  • Vue.set()Responsive new and modified data

  • Calling method: Vue .set( target, key, value )

  • target: The data source to be changed (can be an object or array)

  • key: The specific data to be changed

  • value: The value to be reassigned

Related free learning recommendations: javascript (video)

The above is the detailed content of What to do if vue.set() error occurs. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Related articles

See more