Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@llccing
Created July 26, 2019 06:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save llccing/db2e743a9405bab66898b6e955c7d7a7 to your computer and use it in GitHub Desktop.
Save llccing/db2e743a9405bab66898b6e955c7d7a7 to your computer and use it in GitHub Desktop.
防抖函数
<template>
<Select
:loading="loading"
:remote-method="remoteMethod"
filterable
clearable
placeholder="请选择部门"
remote
style="width:300px;"
v-model="value"
>
<Option :key="index" :value="option.id" v-for="(option, index) in selection">{{option.fullname}}</Option>
</Select>
</template>
<script>
import utils from '@/utils';
export default {
name: 'selectDepart',
props: {
nodeid: Number,
},
data() {
return {
value: '',
selection: [],
loading: '',
// 防抖函数
debounceMethod: null,
};
},
methods: {
remoteMethod(query) {
if (query === '') {
return;
}
this.debounceMethod(query)
},
searchPart(query) {
let data = {
keyword: query,
site_type: 1,
};
this.loading = true;
this.$store
.dispatch('ajaxGet', {
url: '/v1.0/rbac/search_resource',
params: data,
})
.then(res => {
if (res.status == 200) {
this.loading = false;
let objRes = res.data;
console.log(objRes);
this.selection = [];
this.$nextTick(() => {
this.selection = objRes.data;
});
}
});
},
},
mounted() {
// 防抖操作,避免输一个字符就查询一下接口
this.debounceMethod = utils.debounce(username => {
this.searchPart(username);
}, 500);
},
watch: {
value(newVal) {
this.$emit('update:nodeid', Number.parseInt(newVal));
},
},
};
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment