【发布时间】:2018-04-18 09:58:18
【问题描述】:
我的页面网址为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”)。我需要附上我获得的 id,以便新的 url 是(url:“https://text.com/post/get/5”)。我怎样才能提供获得的 id 来获取所需的 json 数据。我在 js 方面非常基础。请帮帮我
【问题讨论】:
标签: javascript jquery vue.js vue-component vue-router