$route.query.id
时间: 2023-12-15 13:03:26 浏览: 48
.query.id是Vue.js中路由传递参数的一种方式,它可以获取到通过query方式传递的参数。在Vue.js中,我们可以通过this.$route.query.id来获取到路由中传递的参数id。例如,如果我们在路由中传递了参数id,那么我们可以通过以下方式获取到它:
```javascript
this.$route.query.id
```
其中,$route是Vue.js中的一个全局对象,它包含了当前路由的信息,包括路由参数、查询参数等。query是其中的一个属性,它包含了通过query方式传递的参数。因此,$route.query.id就是获取到了通过query方式传递的参数id。
相关问题
this.goodsId = this.$route.query.id;什么意思
这是一个Vue.js代码片段,用于获取当前路由中传递的参数id。
在Vue.js中,使用`$route`对象可以获取当前路由的相关信息,包括当前路由的路径、参数、查询参数等。
`$route.query`是一个对象,包含了当前路由中所有的查询参数,例如:`/path?id=123&name=abc`,则`$route.query`将返回一个对象`{id: "123", name: "abc"}`。
而在该代码片段中,`this.$route.query.id`的意思是获取当前路由中名为“id”的查询参数的值,并将其赋值给变量`this.goodsId`。这个查询参数的值可以在路由跳转时通过`<router-link>`或`router.push`方法传递。
// 接收路由跳转传来的id getId() { this.id = this.$route.query.id }, // 获取新的页数 getNewPage(val) { this.currentPage = val }, // 分页获取帖子 getArticleByPage() { var params = { currentPage: this.currentPage, pageSize: this.pagesize, categoryId: this.$route.query.id, source: this.source, parameter: this.parameter } getArticlePage(params).then((res) => { }) },将这三段代码改写到一个async和await函数中
您可以将这三段代码重写为一个使用 async/await 的函数,如下所示:
```javascript
async fetchData() {
try {
// 接收路由跳转传来的id
this.id = this.$route.query.id;
// 获取新的页数
this.currentPage = await this.getNewPageValue();
// 分页获取帖子
var params = {
currentPage: this.currentPage,
pageSize: this.pagesize,
categoryId: this.$route.query.id,
source: this.source,
parameter: this.parameter,
};
await this.getArticlePageData(params);
} catch (error) {
console.error(error);
}
},
async getNewPageValue() {
return new Promise((resolve, reject) => {
resolve(val);
});
},
async getArticlePageData(params) {
try {
await getArticlePage(params);
} catch (error) {
console.error(error);
}
}
```
请注意,为了使这段代码完整,我假设 `getNewPage` 方法返回一个 Promise,并且 `getArticlePage` 是一个异步函数,返回一个 Promise。您需要根据实际情况进行调整和修改。