Home Web Front-end JS Tutorial Use Vue.set to dynamically add object properties in Vue

Use Vue.set to dynamically add object properties in Vue

Jun 05, 2018 am 11:44 AM
vue

Below I will share with you an article on Vue's Vue.set method to dynamically add object attributes. It has a good reference value and I hope it will be helpful to everyone.

When we add a new attribute to an object that is observed in props or data, we cannot add it directly. We must use the Vue.set method.

The Vue.set method is used to add new object properties. If the object to which the attribute is to be added is responsive, then this method can ensure that the attribute is also responsive after being created, and at the same time triggers a view update.

There is no food object here. count attribute, if we want to add the count attribute to it, we must use the Vue.set method instead of writing 'this.food.count = 1'

The above is what I compiled for everyone. I hope it will be helpful to everyone in the future. helpful.

Related articles:

Using vuex under vue-cli (detailed tutorial)

How to use vue-cli to write vue plug-ins

How to use ngrok express to solve the WeChat interface debugging problem

The above is the detailed content of Use Vue.set to dynamically add object properties in Vue. For more information, please follow other related articles on the PHP Chinese website!

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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to use echarts in vue How to use echarts in vue May 09, 2024 pm 04:24 PM

How to use echarts in vue

The role of export default in vue The role of export default in vue May 09, 2024 pm 06:48 PM

The role of export default in vue

How to use map function in vue How to use map function in vue May 09, 2024 pm 06:54 PM

How to use map function in vue

The difference between event and $event in vue The difference between event and $event in vue May 08, 2024 pm 04:42 PM

The difference between event and $event in vue

The difference between export and export default in vue The difference between export and export default in vue May 08, 2024 pm 05:27 PM

The difference between export and export default in vue

The role of onmounted in vue The role of onmounted in vue May 09, 2024 pm 02:51 PM

The role of onmounted in vue

Onmounted in vue corresponds to which life cycle of react Onmounted in vue corresponds to which life cycle of react May 09, 2024 pm 01:42 PM

Onmounted in vue corresponds to which life cycle of react

What scenarios can event modifiers in vue be used for? What scenarios can event modifiers in vue be used for? May 09, 2024 pm 02:33 PM

What scenarios can event modifiers in vue be used for?

See all articles