http的GET方法參數中不能傳列表,接收端的key會變


如下

  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
        })
      })
    },

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM