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

New properties for Vue.js tracking objects

高洛峰
Release: 2016-10-15 10:25:35
Original
1518 people have browsed it

Vue can track changes in ordinary objects.

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

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;
Copy after login

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


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