lrf402788946 5 سال پیش
والد
کامیت
aa4b7a13c4
1فایلهای تغییر یافته به همراه27 افزوده شده و 15 حذف شده
  1. 27 15
      src/views/question.vue

+ 27 - 15
src/views/question.vue

@@ -4,29 +4,29 @@
       <el-col :span="24" class="style">
         <el-form ref="form" :model="form">
           <el-col :span="24" class="topTitle">
-            {{ info.name }}
+            {{ task.name }}
           </el-col>
-          <el-col :span="24" v-for="(item, index) in info.question" :key="index">
+          <el-col :span="24" v-for="(item, index) in task.question" :key="index">
             <el-form-item>
               <span slot="label">{{ index + 1 }} . {{ item.topic }}</span>
             </el-form-item>
-            <span v-if="item.type === '0'">
+            <template v-if="item.type === '0'">
               <el-col :span="24" v-for="(items, index) in item.option" :key="index">
-                <el-radio v-model="form.answer" :label="items.opname">{{ items.opname }}</el-radio>
+                <el-radio v-model="item.answer" :label="items.opname">{{ items.opname }}</el-radio>
               </el-col>
-            </span>
-            <span v-else-if="item.type === '1'">
-              <el-col :span="24" v-for="(items, index) in item.option" :key="index">
-                <el-checkbox-group v-model="form.opname">
+            </template>
+            <template v-else-if="item.type === '1'">
+              <el-checkbox-group v-model="item.answer">
+                <el-col :span="24" v-for="(items, index) in item.option" :key="index">
                   <el-checkbox :label="items.opname">{{ items.opname }}</el-checkbox>
-                </el-checkbox-group>
-              </el-col>
-            </span>
+                </el-col>
+              </el-checkbox-group>
+            </template>
             <span v-else>
               <el-input
                 type="textarea"
                 placeholder="请输入内容"
-                v-model="form.content"
+                v-model="item.content"
                 :autosize="{ minRows: 4, maxRows: 6 }"
                 maxlength="300"
                 show-word-limit
@@ -43,19 +43,31 @@
 </template>
 
 <script>
+import _ from 'lodash';
 export default {
   name: 'index',
   props: {
-    info: null,
+    info: { type: Object, required: true },
     form: null,
   },
   components: {},
-  data: () => ({}),
+  data: () => ({
+    task: {},
+  }),
   created() {},
   computed: {},
   methods: {
     onSubmit() {
-      this.$emit('submit', { data: this.form });
+      this.$emit('submit', this.task);
+    },
+  },
+  watch: {
+    info: {
+      handler(val) {
+        if (_.get(val, `id`)) this.$set(this, `task`, val);
+      },
+      immediate: true,
+      deep: true,
     },
   },
 };