【问题标题】:Update a value in an axios URL in VueJS在 VueJS 中更新 axios URL 中的值
【发布时间】:2023-02-10 19:59:26
【问题描述】:

单击按钮时,我正在尝试更新名为 URL 的 axios 中的“this.counts”值。谁能帮我解决这个问题?谢谢

.get(
          "https://myurl/results.json" +
            query +
            `&num_ranks=$**{this.counts}**` 

data: function () {
    return {
      counts: 2
};

methods: {
    //number added to the Axios URL to display load more results
    loadMore() {
      if (this.loadMore) {
        this.counts += 10;
      }
    },
}   

 <button                
            @click="loadMore">
            Load more {{ counts }}
          </button>

【问题讨论】:

    标签: vue.js axios


    【解决方案1】:

    为 axios API 请求创建一个特定的函数,并在单击按钮时调用它。 (在loadMore()中调用它。)

    <template>
      <button @click="loadMore">Load more {{ counts }}</button>
    </template>
    
    <script>
    export default {
      data() {
        return {
          counts: 0
        }
      },
      methods: {
        loadMore() {
          if (this.loadMore) {
            this.counts += 10;
            this.getMore()
          }
        },
        getMore() {
          // Axios call here
          axios.get("https://myurl/results.json" + query + `&num_ranks=$**{this.counts}**`)
        }
      }
    }
    </script>
    

    【讨论】:

      猜你喜欢
      • 2018-05-04
      • 2017-11-10
      • 2021-03-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-30
      相关资源
      最近更新 更多