Aka*_*kas 2 vue.js laravel-5.5
我已将 id 传递给 url ie。(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>
Run Code Online (Sandbox Code Playgroud)
我假设你没有使用 vue-router。
您可以使用 window.location 属性来获取当前的 url 对象。
您可以使用以下方式获取当前 ID
var id = window.location.href.split('/').pop();
| 归档时间: |
|
| 查看次数: |
4783 次 |
| 最近记录: |