新增路径
{ path: ‘save‘, name: ‘添加讲师‘, component: () => import(‘@/views/edu/teacher/save‘), meta: { title: ‘添加讲师‘, icon: ‘tree‘ } }
修改路径
<router-link :to="‘/teacher/edit/‘+scope.row.id"> <el-button type="primary" size="mini" icon="el-icon-edit">修改</el-button> </router-link>
根据路由和id的值判断是新增还是修改
created(){ this.init() }, watch:{ $route(to,from){ this.init()//监听路由的变化 } },methods:{ init(){ //根据路由和id的值判断是新增还是修改 if (this.$route.params && this.$route.params.id) { //修改,对象初始化 const id = this.$route.params.id this.getInfo(id)//调用对象初始化方法,给对象赋值 }else{ //新增,清空对象 this.teacher = {} } }, }
原文:https://www.cnblogs.com/konglxblog/p/14778956.html