<router
‐
link class
=
"
mui
‐
tab
‐
item
"
:to
=
"
{path:
'
/cms/page/add/
'
,query:{
page: this.
params.
page,
siteId: this.
params.siteId}}
"
>
<el
‐
button type
=
"
primary
"
size
=
"
small
"
>新增页面</el
‐
button>
</router
‐
link>
<el‐button type="primary"@click="go_back">返回</el‐button>
go_back(){
this.
$router.
push({
path:
'
/cms/page/list
'
, query: {
page: this.
$route.
query
.
page,
siteId:this.
$route.
query
.siteId
}
})
}
a、通过在路由上添加key/value串使用this.
$route.
query来取参数,例如:/router1?id
=123 ,/router1?id
=456
可以通过this.
$route.
query
.id获取参数id的值。
b、通过将参数作为路由
一
部分进行传参数使用this.
$route.
params来获取,例如:定义的路由为/router1/:id ,请
求/router1/123时可以通过this.
$route.
params.id来获取,此种情况用this.
$route.
query
.id是拿不到的。
created() {
//从路由上获取参数
this.
params.
page
= Number.
parseInt(this.
$route.
query
.
page||1);
this.
params.siteId
=
this.
$route.
query
.siteId||
''
;
.....
<el‐form :model="pageForm":rules="pageFormRules"label‐width="80px">
pageFormRules: {
siteId:[
{required: true, message:
'
请选择站点
'
, trigger:
'
blur
'
}
],
templateId:[
{required: true, message:
'
请选择模版
'
, trigger:
'
blur
'
}
],
pageName: [
{required: true, message:
'
请输入页面名称
'
, trigger:
'
blur
'
}
],
pageWebPath: [
{required: true, message:
'
请输入访问路径
'
, trigger:
'
blur
'
}
],
pagePhysicalPath: [
{required: true, message:
'
请输入物理路径
'
, trigger:
'
blur
'
}
]
}
<el‐form :model="pageForm":rules="pageFormRules"label‐width="80px"ref="pageForm">
this.
$refs.
pageForm.validate((valid)
=
> {
if (valid) {
alert(
'
提交
'
);
} else {
alert(
'
校验失败
'
);
return false;
}
})
/
*
页面添加
*
/
export const page_add
=
params
=
> {
return http
.requestPost(apiUrl+
'
/cms/page/add
'
,params)
}
this.$confirm('确认提交吗?','提示', {}).then(()=> {})
this.$message({message:'提交成功',type:'success'})
addSubmit(){
this.
$refs.
pageForm.validate((valid)
=
> {
if (valid) {
this.
$confirm(
'
确认提交吗?
'
,
'
提示
'
, {})
.then(()
=
> {
cmsApi.
page_add(this.
pageForm)
.then((res)
=
> {
console.log(res);
if(res.success){
this.
$message({
message:
'
提交成功
'
,
type:
'
success
'
});
this.
$refs[
'
pageForm
'
]
.resetFields();
}else{
this.
$message.error(
'
提交失败
'
);
}
});
});
}
});
}
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |