如何将id绑定到vuejs中的ajax请求URL?

时间:2017-11-06 09:24:45

标签: javascript jquery vue.js vue-component vue-router

我的网页网址为https://test.com/deaileditem.php?id=5

我需要获取此ID并在我的ajax请求结束时附加以获取json数据。

我使用代码

var id = window.location.href.split('=').pop()
             console.log(id)

我的vue js代码是

<script>
still = new Vue({
    el: '#cat',
    data: {
        les: [],
    },


    mounted() {
        var m = this;
         var id = window.location.href.split('=').pop()
             console.log(id)
        $.ajax({
            url: "https://text.com/post/get/id",
            type: "GET",
            dataType: "JSON",

            success: function(e) {
                 m.les = e;
                console.log(e.les)

            },
        });
    },


})
</script>

而不是&#39; id&#39;在网址中(网址:&#34; https://text.com/post/get/id&#34;)。我需要附上我获得的id,以便新的url是(url:&#34; https://text.com/post/get/5&#34;)。如何能够获取获取所需的json数据的id。我在js非常基础。请帮帮我

1 个答案:

答案 0 :(得分:1)

您尚未在id

中添加url

更改

url: "https://text.com/post/get/id",

url: "https://text.com/post/get/" + id,