Home > Web Front-end > Vue.js > body text

What to do if vue.set() error occurs

coldplay.xixi
Release: 2021-01-08 17:27:51
Original
2116 people have browsed it

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)
        }
      }
    }
  }
Copy after login

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)
        }
      }
    }
  }
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!