Practice of el-cascader cascade selector in elementui

Practice of el-cascader cascade selector in elementui

1. Effect

insert image description here

Function: Use the data retrieved from the interface to display the optional items and start with the default option values.

2. Main code

<el-cascader ref="cascaderAddr" :options="rangeArr" :props="optionProps" v-model="plable" @change="handleChange3" style="width: 100%;"></el-cascader>

explain:

(1) The data source does not conform to the official data source and needs to be redirected

insert image description here

But the data source returned by our interface is as follows:

insert image description here

So we need to re-point to the value, label and children values ​​(hence: props="optionProps");

(2) expandTrigger: The expansion method of the secondary menu is click/hover. The default is click.

(3) checkStrictly: Whether to strictly abide by the principle that parent and child nodes are not related to each other

export default {
	data() {
// Delivery location selection source rangeArr: [],
			optionProps: {
				value: 'sguid',
				label: 'address',
				children: 'childs',
				checkStrictly: true,
				expandTrigger: 'hover'
			},
			plable: [], //delivery selection value},
mounted: function() {
//Delivery location this.$axios
			.get('url')
			.then(response => {
				this.rangeArr = response.data.obj;
				console.log('Delivery can choose source aaaa', this.rangeArr);			
			})
			.catch(function(error) {
				// Request failure processing console.log(error);
			});
	//Get the initial value this.$axios.get("url")
	    .then((response) => {
			if (response.data.status == 200){
			    this.plable=response.data.obj.ranges_sguid;//Default selected value }
		})
		 .catch(function (error) { // Request failure processing console.log(error);
	    });
},
methods: {
handleChange3(value) {
			console.log('select id value',value);
			console.log('Select label value',this.plable);
			var thsAreaCode = this.$refs.cascaderAddr.getCheckedNodes()[0].pathLabels;; //Note 2: Get label value console.log('lable',thsAreaCode) // Note 3: The final result is a one-dimensional array object var len=value.length-1;
			this.form.ranges_sguid=value[len];//This is the final modified selected data value to be submitted console.log('guid',this.form.ranges_sguid);
			this.$refs.cascaderAddr.toggleDropDownVisible(); // After selecting, collapse the drop-down interface }
}

This is the end of this article about the practice of el-cascader cascade selector in elementui. For more relevant element el-cascader cascade selector 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:
  • Solution to the cascade selector bug in Vue+ElementUI
  • ElementUI implements cascading selector

<<:  Mysql desktop tool SQLyog resources and activation methods say goodbye to the black and white command line

>>:  HTML sub tag and sup tag

Recommend

Detailed explanation of how to create MySql scheduled tasks in navicat

Detailed explanation of creating MySql scheduled ...

How to use nodejs to write a data table entity class generation tool for C#

Although Microsoft provides T4 templates, I find ...

Multi-service image packaging operation of Dockerfile under supervisor

Writing a Dockerfile Configure yum source cd /tmp...

HTML5+CSS3 header creation example and update

Last time, we came up with two header layouts, on...

Solution to Nginx session loss problem

In the path of using nginx as a reverse proxy tom...

How to query date and time in mysql

Preface: In project development, some business ta...

How to implement Mysql switching data storage directory

How to implement Mysql switching data storage dir...

Detailed tutorial on building a local idea activation server

Preface The blogger uses the idea IDE. Because th...

How to install WSL2 Ubuntu20.04 on Windows 10 and set up the docker environment

Enable WSL Make sure the system is Windows 10 200...

Detailed explanation of jQuery's core functions and event handling

Table of contents event Page Loading Event Delega...

Node+socket realizes simple chat room function

This article shares the specific code of node+soc...

Vue image cropping component example code

Example: tip: This component is based on vue-crop...