首页 > 解决方案 > 在 vue.js 中执行 axios.get 时捕获特定元素

问题描述

在点击 URL 时执行 axios.get 调用时,我想捕获一个元素并将其分配给 lastid -“ http://127.0.0.1:5000/api/products/ ”。我不知道如何捕获一个单一的元素,即“ldd”(如 JSON 格式所示)并将其分配给 vue.js 脚本 lastid 变量。

[
  {
    "ActualPrice": 275, 
    "Category": "Beauty", 
    "ImageURL": "https://beautyme.jpg", 
    "OfferPercentage": 50, 
    "ProductName": "Fogg Deo", 
    "ProductURL": "https://nico.com", 
    "StrikedPrice": 550, 
    "ldd": "5bdd04934d395947f9c04237"
  }, 
  {
    "ActualPrice": 229, 
    "Category": "Beauty", 
    "ImageURL": "https://beautyme.jpg", 
    "OfferPercentage": 50, 
    "ProductName": "Marco, 150ml (Pack of 2)", 
    "ProductURL": "https://nico.com", 
    "StrikedPrice": 460, 
    "ldd": "5bdd04934d395947f9c04237"
  }, 
]
<script>
        var app5 = new Vue({
        el: '#app-5',
        delimiters: ['[[',']]'],
        data: {
            message: [],
            ld: 0,
        },
        methods: {
            loadmore: function () {
              axios.get('http://127.0.0.1:5000/api/products/'+ld)
              .then(response => {
                this.message.push(...response.data);
                lastid = "5bdd04934d395947f9c04237"; //I want to update lastid
                });
            }
        },
        });
        </script>

标签: javascriptvue.js

解决方案


推荐阅读