This commit is contained in:
scammo
2021-08-18 22:59:44 +02:00
parent 513d204d58
commit f0ef4e7f13
7 changed files with 141 additions and 126 deletions

View File

@ -53,10 +53,13 @@
</div>
</template>
<script>
import RequestMixin from "@/mixins/request.mixin"
import ProfileList from "@/components/ProfileList";
export default {
name: "AutoComplete",
mixins: [RequestMixin],
components: {
ProfileList,
},
@ -80,31 +83,6 @@ export default {
};
},
methods: {
async search() {
try {
const request = await this.axios.get(
`${this.apiUrl}/${this.type}s?search=${this.searchText}`,
{
headers: {
Authorization: `Bearer ${localStorage.getItem("token")}`,
},
}
);
if (request.status === 200) {
this.searchResults = request.data[`${this.type}s`];
if (
!this.values
.map((item) => item[this.type].name.toLowerCase())
.includes(this.searchText.toLowerCase())
) {
this.searchResults.unshift({ name: this.searchText });
}
}
} catch (error) {
console.error();
this.showErrorMessage = true;
}
},
addResult(result = false) {
if (!result) result = this.searchResults[0];
if (