【发布时间】:2021-10-06 13:43:19
【问题描述】:
我正在使用 Inertia 在 Vue JS 上实现一个列表,您可以在其中按名称过滤
data() {
return {
selectedUser: this.value,
selected: null,
search: '',
}
},
computed: {
userlist: function(){
return this.users.filter(function(user){
return user.name.toLowerCase().match(this.search.toLowerCase())
});
}
},
和组件
<input class="form-input" placeholder="Search.." v-model="search">
<a href="#" class="block px-4 py-2 text-sm leading-5 text-gray-700 hover:text-gray-900 hover:bg-gray-100 focus:outline-none focus:bg-gray-100 focus:text-gray-900 flex items-center" v-for="user in userlist" :key="user.id" @click.prevent="select(user)">
但是,当我打开组件所在的模态框时,出现错误
Uncaught (in promise) TypeError: Cannot read property 'search' of undefined
我已经硬编码了搜索值,像这样
computed: {
userlist: function(){
return this.users.filter(function(user){
return user.name.toLowerCase().match('John')
});
}
},
并且组件渲染得很好。我没有得到错误可能在哪里,所以任何帮助将不胜感激
【问题讨论】:
-
如果将 v-model 替换为
selected或任何其他值,是否显示相同?
标签: javascript laravel vue.js inertiajs