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

js to realize the rotation of web page pictures

This article shares the specific code of js to re...

How to optimize MySQL index function based on Explain keyword

EXPLAIN shows how MySQL uses indexes to process s...

Node+socket realizes simple chat room function

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

MySQL 8.0.21 installation tutorial under Windows system (illustration and text)

Installation suggestion : Try not to use .exe for...

Detailed discussion of the differences between loops in JavaScript

Table of contents Preface Enumerable properties I...

Personal opinion: Talk about design

<br />Choose the most practical one to talk ...

Detailed example of MySQL data storage process parameters

There are three types of MySQL stored procedure p...

Detailed explanation of transactions and indexes in MySQL database

Table of contents 1. Affairs: Four major characte...

How to implement encryption and decryption of sensitive data in MySQL database

Table of contents 1. Preparation 2. MySQL encrypt...

Detailed explanation of Vue development website SEO optimization method

Because the data binding mechanism of Vue and oth...

Installation and use of mysql mycat middleware

1. What is mycat A completely open source large d...

CSS3 category menu effect

The CSS3 category menu effects are as follows: HT...