【发布时间】:2017-10-13 20:14:33
【问题描述】:
我是 vue.js 的新手。所以我想在我的项目中应用一个过滤器。我在过去的 2 到 3 天尝试这样做..但我不能..谁能帮助我如何这样做..
我有 3 个输入框,一个是经验、expected_ctc 和 profile_role,取决于这 3 个我想显示结果..
这是我的js页面:
const app = new Vue({
el: '#app',
data() {
return {
page: 0,
itemsPerPage: 3,
}
},
components: { Candidate },
methods: {
//custom method bound to page buttons
setPage(page) {
this.page = page-1;
this.paginedCandidates = this.paginate()
},
paginate() {
return this.filteredCandidates.slice(this.page * this.itemsPerPage, this.page * this.itemsPerPage + this.itemsPerPage)
},
},
computed: {
//compute number of pages, we always round up (ceil)
numPages() {
console.log(this.filteredCandidates)
return Math.ceil(this.filteredCandidates.length/this.itemsPerPage);
},
filteredCandidates() {
//filter out all candidates that have experience less than 10
const filtered = window.data.candidates.filter((candidate) => {
if(candidate.experience === 5) {
return false;
}
return true;
})
console.log(filtered);
return filtered;
},
paginedCandidates() {
return this.paginate()
}
}
});
这是我查看页面的按钮:
<div class="container">
<b>Experience:</b><input type="text" v-model="experience" placeholder="enter experience">
<b>Expected CTC:</b><input type="text" v-model="expected_ctc" placeholder="enter expected ctc">
<b>Profile Role:</b><input type="text" v-model="profile_role_id" placeholder="enter role">
<input type="button" name="search" value="search" >
</div>
谁能帮帮我..
提前谢谢..
【问题讨论】:
-
很多问题:Candidate 组件是什么样子的。你在哪里使用它?显示的 v-model 绑定的数据定义在哪里?为什么数据绑定到窗口?!?如果你想使用 vue 过滤,这似乎有点奇怪。
-
其实我不知道如何在vue.js页面中使用v-model来过滤过滤器.....我刚刚在输入框中创建了..v-model..跨度>
-
我将编辑我的问题..你可以看到..我的候选组件看起来如何..
-
您的数据从何而来?你在哪里加载它?为什么它在窗口属性上?甚至可能更相关:您甚至在哪里使用候选组件?
-
它来自vue页面..i import Candidate.vue in my js page import Candidate from './components/Candidate.vue';
标签: vue.js laravel-5.4