Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to add an array page to vue and display it in time

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

Today, I would like to share with you how to add vue array pages to display the relevant knowledge points in time, detailed content, clear logic, I believe that most people still know too much about this knowledge, so share this article for your reference, I hope you can get something after reading this article, let's take a look at it.

How to add an array page and display it in time

Recently in doing vue-related projects, in the process, encountered a lot of problems, some have been solved, some have not been solved, one of the better problems is a comment reply function, click reply, you can get the content and add to the array, but the page will not be displayed in time.

After a lot of Baidu groping, it was finally solved.

Let's have a look together.

/ / newwrite is a defined array / / push into the user name and input, and changeitems//changeitems is the content of the input box I am listening to / this.newwrite.push ({user_id:this.userid, req_content:changeitems}) console.log (this.newwrite)

Because I use a two-dimensional array in some places, this push method can't be displayed on the page in time.

Js Code:

/ / the items here is a two-dimensional array / / responses under multiple comments / / Click to add to the corresponding comment _ this.items [index] .push ({user_name:_this.username, user_id:_this.userid, req_content:text})

Html Code:

{{username}}: {{item}}

Can be passed into the array and cannot be displayed on the page

So I used another method, Vue.set (this.arr, this.arr.length, text).

The this here needs to define the structure in advance.

Js Code:

/ / a = [] / here _ this=this_ this.items [I] = new Array (); _ this.a.push (_ this.items [I]); / / click event: Vue.set (this.a, this.a.length, text)

Html Code:

{{username}}: {{item}}

Then click the reply and it can be displayed on the page in time.

Add an array to an object

This.$set (object, key, array)

For example:

This.$set (this.modelForm, "Authorizers", this.chooseData); these are all the contents of the article "how to add array pages to vue to display in time". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report