Vue binding object, array data cannot be dynamically rendered case detailed explanation

Vue binding object, array data cannot be dynamically rendered case detailed explanation

Project scenario:

Dark Horse Vue project management practice, get product classification, modify data attributes in the tab page of the expansion bar

Problem description:

When you click the +new tag tab, an input box pops up for the user to enter the attributes to be added.

The result is that it cannot be rendered immediately when clicked

async getParametersList() {
      this.cat_id = this.currentSelect[this.currentSelect.length - 1];
      const { data: res } = await this.$http.get(
        `categories/${this.cat_id}/attributes`,
        {
          params: { sel: "many" }
        }
      );
      this.paramasData = res.data;
 
      res.data.forEach(item => {
        item.attr_vals = item.attr_vals ? item.attr_vals.split(" ") : [];
        //Control the display and hiding of the text box item.inputVisible=false
        //The value entered in the text box item.inputValue=''
        console.log(item)
      });
      console.log(this.paramasData);
    },
//Click the button to display the dialog box //Click the button to display the text input box showInput(row) {
      row.inputVisible = true
      // Let the text box automatically get the focus // The function of the $nextTick method is to specify the code in the callback function only after the elements on the page are re-rendered // this.$nextTick((_) => {
      // this.$refs.saveTagInput.$refs.input.focus()
      // })
    },

Cause Analysis:

Refer to this article

https://www.jb51.net/article/222379.htm

It turned out that after obtaining the parameter list, I immediately bound the value bidirectionally, and then added the inputvisible control attribute to the object in each column. As a result, when the button was clicked later, the Inputvisible of each object could not be rendered in real time with the v-if in the input box.

After two-way binding, the property values ​​of the objects in the array are added. There is no way for Vue to bind the getter and setter functions for the objects subsequently added to the array, so there is no way to get real-time rendering.

Solution:

After modifying the data, assign values ​​to the data in data.

Right now

async getParametersList() {
      this.cat_id = this.currentSelect[this.currentSelect.length - 1];
      const { data: res } = await this.$http.get(
        `categories/${this.cat_id}/attributes`,
        {
          params: { sel: "many" }
        }
      );
      
 
      res.data.forEach(item => {
        item.attr_vals = item.attr_vals ? item.attr_vals.split(" ") : [];
        //Control the display and hiding of the text box item.inputVisible=false
        //The value entered in the text box item.inputValue=''
        console.log(item)
      });
      this.paramasData = res.data;
      console.log(this.paramasData);
    },

This is the end of this article about vue binding objects, array data cannot be dynamically rendered. For more related vue binding objects, array data cannot be dynamically rendered, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Vue+elementUI component recursively implements foldable dynamic rendering multi-level sidebar navigation
  • Solution to the problem that the src of img in Vue is not displayed when dynamically rendered
  • Dynamic rendering example of the Vue navigation bar
  • Example code for Vue form binding (radio button, selection box (single selection, multiple selection, dynamic options rendered with v-for)
  • Detailed explanation of VUE Element-UI multi-level menu dynamic rendering components

<<:  Quickly solve the problem of garbled characters and jump lines in mysql exported scv files

>>:  Quickly solve the problems of incorrect format, slow import and data loss when importing data from MySQL

Recommend

Detailed tutorial on installing Python 3.6.6 from scratch on CentOS 7.5

ps: The environment is as the title Install possi...

Modify the boot time of grub in ubuntu

The online search to modify the grub startup time...

How to configure the same domain name for the front and back ends of nginx

This article mainly introduces the method of conf...

JavaScript Regular Expressions Explained

Table of contents 1. Regular expression creation ...

25 Tools to Improve Website Usability and Conversion Rates

For a website, usability refers to whether users c...

Deploy Varnish cache proxy server based on Centos7

1. Varnish Overview 1. Introduction to Varnish Va...

Implementation of Single Div drawing techniques in CSS

You can often see articles about CSS drawing, suc...

CSS implements Google Material Design text input box style (recommended)

Hello everyone, today I want to share with you ho...

Detailed introduction and usage examples of map tag parameters

Map tags must appear in pairs, i.e. <map> .....

Modify the style of HTML body in JS

Table of contents 1. Original Definition 2. JS op...

Vue uses drag and drop to create a structure tree

This article example shares the specific code of ...

HTML tags: sub tag and sup tag

Today I will introduce two HTML tags that I don’t...

How to solve the problem of margin overlap

1. First, you need to know what will trigger the v...