如何在页面第一次加载时,让 getDataList 使用查询条件(人人专业版)
版本:renren-security 2.1 |
开发环境: |
我的想法是在这个入口页面打开后,先去后台取出项目名称,并使用第一个项目作为默认查询条件,然后根据项目名称取出相关的数据。现在的问题是:
页面加载时,取数据的方法(getDataList)并没有使用使用这个过滤条件,人工点击查询按钮是则可以。我需要怎么做才能达到预期的效果呢?
如图,页面加载时项目列表已经取出了,默认查询项目也设置成功了。
img[//cdn.renren.io/0fa78201901251012596389.PNG]
[hr]
相关代码
[pre]
methods: {
init () {
this.$nextTick(() => {
Promise.all([
this.getProjectList()
]).then(() => {
if (this.projectList.length > 0) {
this.dataForm.projectId = this.projectList[0].id
}
})
})
},
// 获取项目列表
getProjectList () {
return this.$http.get('/worktime/project/my-projects').then(({ data: res }) => {
if (res.code !== 0) {
return this.$message.error(res.msg)
}
this.projectList = res.data
}).catch(() => {})
}
},
created () {
this.init()
}
[/pre]