vue项目中常用方法

1.字符串转数组

split();

2.数组转字符串

toString();join();toLocalstring();String()

3.去重

unique(str) {
			let arr = str.split(',');
			return Array.from(new Set(arr)).toString(); // 利用Array.from将Set结构转换成数组
		},

4.删除多余逗号

delateDouhao(str1, str2) {
			let arr1 = str1.split(',');
			let arr2 = [];
			arr1.map((item) => {
				if (item !== '' && item != undefined) {
					arr2.push(item);
				}
			});
			str2 = arr2.join(',');
			return str2;
		},

5.字符串返回符合条件的值

strToVal(str, val) {
			let str1 = str.split(',');
			let str2 = str1.filter((item) => item.includes(val));
			return str2.join(',');
		},

6. 对象赋key值

	objFuzhi(arrA, arrB) {
		Object.keys(arrA).forEach((key) => {
			arrA[key] = arrB[key] || arrA[key];
		});
	},

7.对象赋值

A,B均为对象,扩展运算符,
A= { …A, …B};

8.判断undefined和null

let A = ''
let exp = undefined;
	if ( A=== exp) {
			//
			return undefined
	} 
	if ( A=== null) {
			//
			return null
	} 
	

9.遍历对象

for (let variable in this.searchForm) {}
Object.keys(this.spanData1).map((key) => {})

你可能感兴趣的:(vue,JavaScript,es6)