跳转回列表页
top.frames[0].locationj.href = "/page/supplier_store"; // js跳转的知识
或者
this.$router.back(); //vue router里的知识
提交成功后不跳转在本页面刷新
window.location.href = "/page/supplier_store";
this.$router.go(0);
项目场景是这样的:
添加和修改的click事件绑定的同一个,但是以ID 为判断条件走不同的接口
view 代码:
<el-button type="primary" class="btn btnsubmit" @click="addSupplier('back')">保存</el-button>
<el-button type="primary" class="btn" @click="addSupplier('next')" v-show="revisable">保存录入下一条</el-button>
js代码
addSupplier(p){
this.$refs.ruleForm.validate(async (valid) => {
if (valid) {
this.ruleForm2 = JSON.stringify(this.ruleForm);
this.ruleForm2 = JSON.parse(this.ruleForm2);
this.ruleForm2.categoryIds = this.ruleForm.categoryIds.join(',');
try {
if(this.supplierId){
// 如果有id则证明是编辑
this.ruleForm2.id = this.supplierId;
const {data:{code,msg}} = await srmServices.updateSupplier(this.ruleForm2);
this.code = code;
this.msg = msg;
}else{
// 否则为新增
const {data:{code,msg}} = await srmServices.addSupplier(this.ruleForm2);
this.code = code;
this.msg = msg;
}
} catch (e) {
alert(e);
}
}
if(this.code == 0){
alert('保存成功!');
}else{
alert(this.msg);
}
if(p == 'back'){
this.$router.back();
// top.frames[0].location.href = "/page/supplier_store";
}else if(p == 'next'){
// this.$router.go(0);
window.location.href ="/page/add_supplier";
}
});
},