Home >Web Front-end >JS Tutorial >New properties for Vue.js tracking objects

New properties for Vue.js tracking objects

高洛峰
高洛峰Original
2016-10-15 10:25:351519browse

Vue can track changes in ordinary objects.

<ul id="repeat-object" class="demo">
  <li v-for="value in object">
    {{ $key }} : {{ value }}  </li></ul>

When traversing objects, it traverses according to the results of Object.keys(), but there is no guarantee that its results will be consistent under different JavaScript engines.

But if you want to add an attribute dynamically. For example,

obj[&#39;addProp&#39;] = &#39;abcd&#39;

vue has no way to track changes in the object.

You should use the $set method at this time and let Vue establish tracking. The first parameter is the value expression. , the second one is the value to be set.

this.$set("obj[&#39;addProp&#39;]", &#39;abcd&#39;)


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