可能会用到的函数方法

文章主要自用

find()和findIndex()函数(array数组)

代码参考原链接:https://blog.csdn.net/qq_27674439/article/details/107693074

**find()**函数用来查找目标元素,找到就返回该元素,找不到返回undefined
**findIndex()**函数也是查找目标元素,找到就返回元素的位置,找不到就返回-1。

他们的都是一个查找回调函数。
查找函数有三个参数。
value:每一次迭代查找的数组元素。
index:每一次迭代查找的数组元素索引。
arr:被查找的数组。

var stu=[
		{
		   name:'张三',
		   gender:'男',
		   age:25
		},
		{
		   name:'李四',
		   gender:'男',
		   age:28
		},
		{
		   name:'王五',
		   gender:'男',
		   age:27
		}
  ]
stu.find(item=>item.name=='李四')  
//返回的是{name:"李四",gender:'男',age=28}
stu.findIndex(item=>item.name=='李四')
//返回的是索引下标:1

watch监听代替input的foucs(),this.$refs.inputRef.focus()也可以主动触发watch监听的属性

参考链接:自己写的组件

 watch: {
    filterText(val) {
	//this.$refs.tree.filter(val);触发el-tree的:filter-node-method="filterNode"监听属性
	   this.$refs.tree.filter(val);
	 },
  },
...

SelectVisible() {
  this.$refs.inputRef.focus()
 },
 // 过滤
  filterNode(value, data) {
     if (!value) return true;
     return data.name.indexOf(value) !== -1;
  },

你可能感兴趣的:(vue.js,javascript)