【发布时间】:2019-03-31 08:00:28
【问题描述】:
背景
我正在将一组对象传递给材料自动完成功能,可以在here 中找到它。
当我第一次在列表中选择一个项目时,它会引发错误,然后如果我再次单击该项目,它会按预期选择它。每次单击自动完成中的项目时,都会重复相同的过程。
示例错误
[Vue 警告]:“输入”的事件处理程序出错:“TypeError:不能 读取未定义的属性“构造函数”
示例代码
<template>
<md-autocomplete
v-model="customer"
:md-options="customers"
@md-changed="getCustomers"
@md-opened="getCustomers"
@md-selected="getSelected"
>
</md-autocomplete>
</template>
<script>
data: () => ({
customers: [],
customer: "", // I also tried making this a {}
}),
methods: {
getCustomers(searchTerm) {
this.customers = new Promise(resolve => {
if (!searchTerm) {
resolve(this.GET_CUSTOMERS);
} else {
const term = searchTerm.toLowerCase();
this.customers = this.GET_CUSTOMERS.filter(({ email }) => {
email.toLowerCase().includes(term);
});
resolve(this.customers);
}
});
},
getSelected() {
console.log(this.customer);
},
}
</script>
数据示例
GET_CUSOTMERS: [
{ client_id: 1, email: "example@example.com" },
{ client_id: 2, email: "example@example.com" }
];
问题
这个错误是什么意思,我该如何解决?我读过几年前通过这个错误从材料中使用自动完成的角度存在一个错误,但我乐观地认为这目前是可修复的,而不是材料 vue 的错误。
【问题讨论】:
-
您是否尝试将客户数组填充到安装的挂钩中?
-
我没有,我试试看。
-
我试过了,它仍然给我同样的问题。
标签: javascript vue.js vuejs2 vue-material