async handleSubmit() { this.isSubmiting = true; let postData = { ...this.form, positionNo: this.positionNo }; const data = await this.$axios.post( "/tax/temp/wechat/user/addUserInfo", postData ); if (data.success) { this.$router.push({ name: "register", query: { positionNo: this.positionNo, idNo: this.form.idNo }, }); } else { this.isSubmiting = false; } },在register页面该如何获取并赋值 this.$router.push({ name: "register", query: { positionNo: this.positionNo, idNo: this.form.idNo }, });带过来的值
时间: 2024-04-11 17:27:20 浏览: 19
在 `register` 页面中,你可以使用 `$route` 对象来获取传递过来的参数。具体的代码如下:
```javascript
export default {
data() {
return {
positionNo: null,
idNo: null,
};
},
created() {
this.positionNo = this.$route.query.positionNo;
this.idNo = this.$route.query.idNo;
},
};
```
在上述代码中,我们通过 `this.$route.query` 来获取传递过来的参数,然后将它们分别赋值给 `positionNo` 和 `idNo` 变量。
接下来,你就可以在 `register` 页面中使用这两个变量进行操作了。希望对你有所帮助!如果还有其他问题,请随时提问。
相关问题
优化下面代码getCarbonTotalNumber() { let _this = this let carType = {carType: this.vType == 'noType' ? "" : this.vType} getCarbonDayNumber(carType).then(response => { _this.count.end = response.data }); setTimeout(function () { _this.count.start = _this.count.end }, 100) }
这段代码可以进行一些优化:
1. 可以使用箭头函数来避免使用_this = this:
```
getCarbonTotalNumber() {
let carType = {carType: this.vType == 'noType' ? "" : this.vType}
getCarbonDayNumber(carType).then(response => {
this.count.end = response.data
});
setTimeout(() => {
this.count.start = this.count.end
}, 100)
}
```
2. 可以使用async/await来避免使用回调函数:
```
async getCarbonTotalNumber() {
let carType = {carType: this.vType == 'noType' ? "" : this.vType}
let response = await getCarbonDayNumber(carType)
this.count.end = response.data
setTimeout(() => {
this.count.start = this.count.end
}, 100)
}
```
3. 可以使用Promise.all来同时调用多个接口:
```
async getCarbonTotalNumber() {
let carType = {carType: this.vType == 'noType' ? "" : this.vType}
let [response1, response2] = await Promise.all([
getCarbonDayNumber(carType),
getCarbonWeekNumber(carType)
])
this.count.end = response1.data + response2.data
setTimeout(() => {
this.count.start = this.count.end
}, 100)
}
```
注意:这些代码都是基于假设你已经正确地导入了相关的函数和变量。
getList () { this.loading = true; this.$http.contentScript .getAllContentScript({ current: this.pageForm.currentPage, size: this.pageForm.pageSize, ...this.searchData, }) .then((res) => { this.loading = false; this.tableData = res; this.$refs.plTable.reloadData(this.tableData); }) .catch((err) => { this.loading = false; }); },代码优化
可以将代码进行如下的优化:
1. 使用 async/await 来避免回调嵌套和提高代码的可读性;
2. 将请求参数放入一个对象中,以方便管理和维护;
3. 使用 try/catch 块来处理异常情况;
4. 在请求开始和结束时设置 loading 状态,以提高用户体验。
优化后的代码如下:
```
async getList() {
try {
this.loading = true;
const params = {
current: this.pageForm.currentPage,
size: this.pageForm.pageSize,
...this.searchData
};
const res = await this.$http.contentScript.getAllContentScript(params);
this.tableData = res;
this.$refs.plTable.reloadData(this.tableData);
} catch (err) {
console.error(err);
} finally {
this.loading = false;
}
}
```
通过这样的优化,代码变得更加简洁和易于维护,同时也提高了代码的可读性和可维护性。