要實現一個功能:從頁面A跳轉到頁面B,並且頁面A的參數要傳遞到頁面B,B使用傳過來的參數。
從A到B。
其實就是2步走:1,A傳遞參數。2,B接受參數。
一、頁面跳轉、傳遞參數
在A頁面的對應按鈕,寫上一個方法,點擊的時候調用這個方法,進行跳轉。
# content of A
<el-button size="mini" icon="el-icon-zoom-in"
@click.native="goto_report_log(scope.row.job_name)">查看報告&日志
</el-button>
... ...
# 寫上對應的方法
goto_report_log(job_name) {
// 點擊跳轉到報告頁
this.$router.push(
{
path: '/manage/testReportAndLogo',
query: {
job_name: job_name
}
}
)
}
這時候,點擊按鈕就可以調轉到B頁面了。
二、接收參數
首先,頁面B的html對應的字段要添加好,這是前提。
<el-form-item label="Job名稱" labelWidth="110px">
<el-input placeholder="輸入job名稱" v-model="this.job_name"> #使用拿到的值
</el-input>
</el-form-item>
... ...
export default {
data() {
return {
job_name: "", # 存放A傳過來的值
... ...
# 接着寫上對應的方法
methods: {
getParams() {
this.job_name = this.$route.query.job_name # 這里可以用this.$route.query拿到值
... ...
created() {
this.getParams(); # 放在created里調用即可
},
很簡單,做個記錄。