gpt4 book ai didi

vue.js - Laravel +Vue,如何在vue中获取url参数

转载 作者:行者123 更新时间:2023-12-03 09:02:37 25 4
gpt4 key购买 nike

我已将 id 传递给 url,即。 (http://127.0.0.1:8000/admin/article/32)。现在我想在 vue 中获取该 id 以仅获取该 id 的数据,但我不知道在 vue 中获取该 id

我的 vue 脚本在下面

 <script>

export default{

data() {
return{

articles : [],
article: {
id :'',
title : '',
body : '',
date :''
},
article_id: ''
};
},

created() {
this.fetchArticles();
},

methods: {
fetchArticles() {
var page_url = 'http://127.0.0.1:8000/api/admin/article/'+ I want the parameter id here;
fetch(page_url)
.then(res => res.json())
.then(res => {

this.article = res.data;
})

.catch(err => console.log(err));
}

}
};
</script>

最佳答案

我假设您没有使用 vue-router。

您可以使用window.location属性来获取当前的url对象。

您可以使用以下方式获取当前 ID var id = window.location.href.split('/').pop();

关于vue.js - Laravel +Vue,如何在vue中获取url参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49233195/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com