2018-11-28 16:49:46 +08:00
|
|
|
<template>
|
|
|
|
|
<d2-container
|
2018-11-29 10:59:02 +08:00
|
|
|
:filename="filename"
|
2018-11-28 16:49:46 +08:00
|
|
|
type="card"
|
2018-11-29 10:14:44 +08:00
|
|
|
class="page">
|
2018-11-28 19:43:04 +08:00
|
|
|
<el-form
|
|
|
|
|
ref="form"
|
|
|
|
|
:model="form"
|
|
|
|
|
label-width="80px"
|
2018-11-29 10:14:44 +08:00
|
|
|
class="page--form">
|
2018-11-28 16:49:46 +08:00
|
|
|
<el-form-item label="姓名">
|
|
|
|
|
<el-input v-model="form.name"/>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
<el-form-item label="地址">
|
|
|
|
|
<el-input type="textarea" v-model="form.address"/>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
<el-form-item>
|
|
|
|
|
<el-button type="primary" @click="handleSubmit">修改</el-button>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
</el-form>
|
|
|
|
|
</d2-container>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
2018-11-29 10:14:44 +08:00
|
|
|
import base from './mixins/index'
|
2018-11-28 16:49:46 +08:00
|
|
|
export default {
|
2018-11-29 10:14:44 +08:00
|
|
|
mixins: [
|
|
|
|
|
base
|
|
|
|
|
],
|
2018-11-29 10:59:02 +08:00
|
|
|
data () {
|
|
|
|
|
return {
|
|
|
|
|
filename: __filename
|
|
|
|
|
}
|
|
|
|
|
},
|
2018-11-28 19:43:04 +08:00
|
|
|
// 第一次进入或从其他组件对应路由进入时触发
|
|
|
|
|
beforeRouteEnter (to, from, next) {
|
|
|
|
|
const id = to.params.id
|
|
|
|
|
if (id) {
|
2019-02-06 15:49:47 +08:00
|
|
|
next(instance => {
|
|
|
|
|
instance.resetFormData()
|
|
|
|
|
instance.getFormData(id)
|
2018-11-28 19:43:04 +08:00
|
|
|
})
|
2018-12-15 09:40:54 +08:00
|
|
|
} else {
|
2018-11-28 19:43:04 +08:00
|
|
|
next(new Error('未指定ID'))
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
// 在同一组件对应的多个路由间切换时触发
|
|
|
|
|
beforeRouteUpdate (to, from, next) {
|
|
|
|
|
const id = to.params.id
|
|
|
|
|
if (id) {
|
|
|
|
|
this.resetFormData()
|
|
|
|
|
this.getFormData(id)
|
|
|
|
|
next()
|
|
|
|
|
} else {
|
|
|
|
|
next(new Error('未指定ID'))
|
|
|
|
|
}
|
2018-11-28 16:49:46 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style lang="scss">
|
2018-11-29 10:14:44 +08:00
|
|
|
.page {
|
|
|
|
|
.page--form {
|
2018-11-28 16:49:46 +08:00
|
|
|
max-width: 460px;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</style>
|