In-depth explanation of Vue multi-select list component

In-depth explanation of Vue multi-select list component

A Multi-Select is a UI element that lists all options and allows users to make multiple selections using the Ctrl/Shift keys. This is a common design element. Sometimes, in order to save space, we will collapse the options into a Combo Box. To facilitate user operation, this component will also add two buttons, Select All and Clear All, allowing users to quickly select or clear the selection. This UI element was previously used in the Correlation Plot App.

Registering Components

Registering the Multi-Select component is as simple as copying and pasting the encapsulated code. It is recommended to register global components here.

This element was designed with two modes in mind: The first is that each click on a new option will keep the old options and add the new one, as shown in the example graphic above. This is a more common method. The second is that each time you click a new option, the old option is cleared and only the new option is retained. If you use this method to make multiple selections, you need to use the Ctrl/Shift key. This design makes it easy for users to eliminate old options with each click. If you use the second method, you need to replace the event @click.exact="AddToOrDeleteFromSelectedColumns" with @click.exact="ClickOnColumnListItem"

<script type="text/x-template" id="multi-select-template">
…
   <tr v-for = "(item,index) in columns" 
     @click.exact="AddToOrDeleteFromSelectedColumns"
     @click.shift.exact="AddMultipleToSelectedColumns"
     @click.ctrl.exact="AddToOrDeleteFromSelectedColumns"
     :title="function(item){if(item.longname){return 'Short Name: ' + item.name + '\n----------------\n' + item.longname}else{return item.name}}(item)"
     class="column-list-entry">
   ...
   </tr>
</script>
<script>
Vue.component("multi-select", {
  template: "#multi-select-template",
…
</script>

Calling Components

Add custom tags directly Call the component.

<multi-select :legend_name="legend_name"
       :columns="columns"
       :selected_columns="selected_columns"
       @update_selected_columns="onSelectedColumnsChange">
</multi-select>

Passing Data

Finally, data needs to be passed to the component. We can use v-bind to dynamically bind data to the data of the parent component.

In props, legend_name is bound to the name that Multi-Select needs to display, columns is bound to the options of Multi-Select, and selected_columns is bound to the currently selected item. In addition, we also need to define the event "onSelectedColumnsChange" in the parent instance to refresh the display of the Multi-Select component.

data: function(){
   return {
     legend_name: "Input Columns",
     columns: 
     [
       {"name":"A","longname":"Copper"},
       {"name":"B","longname":"Aluminum Aluminum"},
       {"name":"C","longname":"Calcium"},
       {"name":"D","longname":"Calcium"},
   ],
     selected_columns: [],
   }
 },
... 
methods:{ 
   onSelectedColumnsChange:function(new_columns) {
     this.selected_columns = new_columns;
   },
 },
...

This concludes this article on the in-depth explanation of the Vue multi-select list component. For more relevant Vue multi-select list component content, 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 Element front-end application development tree list component
  • Sample code of the tab-list category switching product list component based on Vue
  • Vue Element UI custom description list component

<<:  How to set Tomcat as an automatically started service? The quickest way

>>:  CentOS 6.5 i386 installation MySQL 5.7.18 detailed tutorial

Recommend

CSS flex several multi-column layout

Basic three-column layout .container{ display: fl...

Cross-browser development experience summary (I) HTML tags

Add a DOCTYPE to the page Since different browser...

Users need to know why

When I was in the securities company, because the ...

How to install JDK 13 in Linux environment using compressed package

What is JDK? Well, if you don't know this que...

A brief analysis of MySQL locks and transactions

MySQL itself was developed based on the file syst...

Use href to simply click on a link to jump to a specified place on the page

After clicking the a tag in the page, you want to ...

MySQL 5.7.18 winx64 installation and configuration method graphic tutorial

The installation of compressed packages has chang...

Docker installation tomcat dubbo-admin instance skills

1. Download the tomcat image docker pull tomcat:8...

How to modify iTunes backup path under Windows

0. Preparation: • Close iTunes • Kill the service...

Some tips on deep optimization to improve website access speed

<br />The website access speed can directly ...

How to use the Fuser command in Linux system

What is Fuser Command? The fuser command is a ver...

How to implement Mysql scheduled task backup data under Linux

Preface Backup is the basis of disaster recovery....

Do you know the common MySQL design errors?

Thanks to the development of the Internet, we can...

Docker image loading principle

Table of contents Docker images What is a mirror?...