Eventually I want to be able to use both the entire person object and its properties in the template."> "Using the v-for directive for array element and attribute destructuring"-PHP Chinese Network Q&A
"Using the v-for directive for array element and attribute destructuring"
P粉420958692
P粉420958692 2023-11-05 17:37:54
0
1
537

When using an object array, is it possible to simultaneously assign the current object to a variable and deconstruct its properties in av-forloop? like this:

Ultimately I would like to be able to use both the entirepersonobject and its properties in the template.

P粉420958692
P粉420958692

reply all (1)
P粉115840076

As far as I know, you can't do both at the same time.

However, you can deconstruct it, for example:

You can then access the correct element via the index:persons[index].


Example:

new Vue({ el: "#app", data: { todos: [{ text: "Learn JavaScript", done: false }, { text: "Learn Vue", done: false }, { text: "Play around in JSFiddle", done: true }, { text: "Build something awesome", done: true } ] }, methods: { toggle: function(index) { this.todos[index].done = !this.todos[index].done } } })
body { background: #20262E; padding: 20px; font-family: Helvetica; } #app { background: #fff; border-radius: 4px; padding: 20px; transition: all 0.2s; } li { margin: 8px 0; } h2 { font-weight: bold; margin-bottom: 15px; } del { color: rgba(0, 0, 0, 0.3); }
 

Todos:

    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!