如何在 vuejs 中将 id 绑定到 ajax 请求 url?
How can I bind an id to an ajax request url in vuejs?
我有 url 页面作为 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>
而不是 url 中的 'id'(url:“https://text.com/post/get/id"). I need to attach the id I obtained so that new url is ( url: "https://text.com/post/get/5”)。我怎样才能提供获得的 id 以获得所需的 json 数据。我对js非常基础。请帮助我
您还没有在 url
中附加 id
改变
url: "https://text.com/post/get/id",
到
url: "https://text.com/post/get/" + id,
我有 url 页面作为 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>
而不是 url 中的 'id'(url:“https://text.com/post/get/id"). I need to attach the id I obtained so that new url is ( url: "https://text.com/post/get/5”)。我怎样才能提供获得的 id 以获得所需的 json 数据。我对js非常基础。请帮助我
您还没有在 url
id
改变
url: "https://text.com/post/get/id",
到
url: "https://text.com/post/get/" + id,