EditComposition.vue 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <template>
  2. <div class="edit-composition">
  3. <el-form
  4. ref="modalFormComp"
  5. :model="modalForm"
  6. :rules="rules"
  7. :key="modalForm.id"
  8. label-width="100px"
  9. >
  10. <el-form-item prop="topicName" label="题目名称:">
  11. <el-input
  12. v-model="modalForm.topicName"
  13. type="textarea"
  14. :autosize="{ minRows: 2, maxRows: 5 }"
  15. resize="none"
  16. placeholder="请输入题目名称"
  17. clearable
  18. ></el-input>
  19. </el-form-item>
  20. </el-form>
  21. </div>
  22. </template>
  23. <script>
  24. const initModalForm = {
  25. id: "",
  26. topicName: ""
  27. };
  28. export default {
  29. name: "edit-composition",
  30. props: {
  31. instance: {
  32. type: Object,
  33. default() {
  34. return {};
  35. }
  36. }
  37. },
  38. data() {
  39. return {
  40. modalForm: { ...initModalForm },
  41. rules: {
  42. topicName: [
  43. {
  44. required: true,
  45. message: "请输入题目名称",
  46. trigger: "change"
  47. }
  48. ]
  49. }
  50. };
  51. },
  52. mounted() {
  53. this.initData(this.instance);
  54. },
  55. methods: {
  56. initData(val) {
  57. const valInfo = val.parent || val;
  58. this.modalForm = { ...valInfo };
  59. },
  60. async submit() {
  61. const valid = await this.$refs.modalFormComp.validate().catch(() => {});
  62. if (!valid) return;
  63. this.modalForm.topicName = this.modalForm.topicName.trim();
  64. this.$emit("modified", this.modalForm);
  65. }
  66. }
  67. };
  68. </script>