聊一聊vue中预览数据回填以后根据答案的多选和单选动态显示

        在项目中,遇到点击预览按钮,显示当前题目的详情,当选择的题目的答案是多选的是动态显示多选的答案,选择单选就动态显示单选的答案,具体效果如图所示

点击单选题的预览

 点击多选题的预览

 

具体代码:

// 父组件
</template>
  <el-button type="text" @click="hPreview(scope.row)">预览</el-button>
  <!-- 题目预览 -->
  <el-dialog title="题目预览" :visible.sync="showPreviewDialog">
     <QuestionsPreview :row="row" v-if="showPreviewDialog"></QuestionsPreview>
  </el-dialog>
</template>

<scirtp>
 data(){
  return:{
   showPreviewDialog: false,
   row:row
   }
  },
method:{
 async hPreview(row) {
    this.showPreviewDialog = true
    this.row = row
  }
}
</scirtp>


// 子组件
<template>
  <div class="container">
    <el-row>
      <el-col :span="24">
        <div v-if="tabeList.questionType === '1'">
          <el-row>【题干】:</el-row>
          <el-row><div v-html="tabeList.question"></div></el-row>
          <el-row>单选题选项: (以下选中的选项为正确答案)</el-row>
          <el-radio-group v-model="radio">
            <el-row v-for="item in tabeList.options" :key="item.id">
              <el-radio-group>
                <!-- 不能选的组 -->
                <el-radio v-if="item.isRight === 0" :label="item.isRight">{{ item.title }}</el-radio>
              </el-radio-group>
              <!-- 默认选中的组 -->
              <el-radio v-if="item.isRight === 1" :label="item.isRight">{{ item.title }}</el-radio>
            </el-row>
          </el-radio-group>
        </div>
        <div v-if="tabeList.questionType === '2'">
          <el-row>【题干】:</el-row>
          <el-row><div v-html="tabeList.question"></div></el-row>
          <el-row>多选题选项: (以下选中的选项为正确答案)</el-row>
          <el-row v-for="item in tabeList.options" :key="item.id">
            <el-checkbox-group v-model="checkeList">
              <!-- 不能选的组 -->
              <el-checkbox-group v-model="checkeList1">
                <el-checkbox v-if="item.isRight === 0" :label="item.isRight" @click.native.prevent="">{{
                  item.title
                }}</el-checkbox>
              </el-checkbox-group>
              <!-- 默认选中的组 -->
              <el-checkbox v-if="item.isRight === 1" :label="item.isRight" @click.native.prevent="">{{
                item.title
              }}</el-checkbox>
            </el-checkbox-group>
          </el-row>
        </div>
        <div v-if="tabeList.questionType === '3'">
          <el-row>【题干】:</el-row>
          <el-row><div v-html="tabeList.question"></div></el-row>
          <el-row><div v-html="tabeList.answer"></div></el-row>
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { detail } from '@/api/hmmm/questions.js'
export default {
  data() {
    return {
      tabeList: {},
      boolean: 'none',
      radio: 1,
      checkeList: [1],
      checkeList1: false
    }
  },
  props: {
    row: {
      type: Object,
      default: () => {}
    }
  },
  async created() {
    console.log('row', this.row)
    const res = await detail(this.row)
    this.tabeList = res.data
    console.log(res)
  },
  methods: {
    // 试题类型
    questionType(data) {
      if (data === '1') {
        return '单选'
      } else if (data === '2') {
        return '多选'
      } else {
        return '简单'
      }
    }
  }
}
</script>

<style scoped lang="less"></style>

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值