如下
async initTable() { await getHostAttributesForUser({'username': this.username}).then(response => { this.listQuery.user_preferences = response.data.preferences # 這里是一個列表this.preference_index_list = response.data.preference_index_list this.colConfigs = response.data.colConfigs getHost(this.listQuery).then(response => { this.tableData = response.data.items this.total = response.data.total }) }) },
實際轉換發送的請求為:
http://localhost:9528/dev-api/cmdb/host/get?node_key=saas&page=1&limit=10&user_preferences[]=公網IP&user_preferences[]=VPC私有IP&user_preferences[]=vCPU 核數&user_preferences[]=內存&user_preferences[]=實例計費方式&user_preferences[]=系統類型
服務端接收到的request.GET內容為
<QueryDict: {'node_key': ['saas'], 'page': ['1'], 'limit': ['10'], 'user_preferences[]': ['公網IP', 'VPC私有IP', 'vCPU 核數', '內存', '實例計費方式', '系統類型']}>
解決方法
async initTable() { await getHostAttributesForUser({'username': this.username}).then(response => { this.listQuery.user_preferences = _.join(response.data.preferences, ',') #將列表轉換成字符串 this.preference_index_list = response.data.preference_index_list this.colConfigs = response.data.colConfigs getHost(this.listQuery).then(response => { this.tableData = response.data.items this.total = response.data.total }) }) },