使用vue+element ui完成的考试测试功能Demo

这篇具有很好参考价值的文章主要介绍了使用vue+element ui完成的考试测试功能Demo。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

根据api传回来的数据渲染试卷页面

<template>
  <div>
    <h2>{{ paper.tName }}</h2>
    <p>{{ paper.tDesc }}</p>
    <el-form ref="form" :model="answers" label-width="120px">
      <!-- <el-row v-for="(question, index) in questions" :key="question.tid"> -->
      <el-row v-for="(question, index) in questions" :key="question.tid" :id="'question-' + index">

        <el-col :span="24" >
          <h3 v-if="question.tType===1">【单选题】{{ index + 1 }}. {{ question.tExplain }}</h3>
          <h3 v-else-if="question.tType===4">【多选题】{{ index + 1 }}. {{ question.tExplain }}</h3>
          <h3 v-if="question.tType===3">【问答题】{{ index + 1 }}. {{ question.tExplain }}</h3>
          <h3 v-if="question.tType===2">【判断题】{{ index + 1 }}. {{ question.tExplain }}</h3>
        </el-col>

        <el-col :span="24">

          <!-- 单选 -->
          <el-radio-group v-if="question.tType === 1" v-model="answers[question.tid]">
            <el-radio v-for="option in question.topicSelect" :key="option.tselect" :label="option.tselect">
              {{ option.topics }}
            </el-radio>
          </el-radio-group>

          <!-- 多选 -->
          <el-checkbox-group v-else-if="question.tType === 4" v-model="answers[question.tid]">
            <el-checkbox v-for="option in question.topicSelect" :key="option.tselect" :label="option.tselect">
              {{ option.topics }}
            </el-checkbox>
          </el-checkbox-group>

          <!-- 问答 -->
          <el-input style="width: 300px;" v-else-if="question.tType === 3" v-model="answers[question.tid]"></el-input>

          <!-- 判断 -->
          <el-radio-group v-else-if="question.tType === 2" v-model="answers[question.tid]">
            <el-radio label="true">正确</el-radio>
            <el-radio label="false">错误</el-radio>
          </el-radio-group>
        </el-col>
      </el-row>
    </el-form>
    <el-button style="margin-top: 10px;" type="primary" @click="submitAnswers">提交答案</el-button>

    <DatiKa :questions="questions" :answers="answers"></DatiKa>
  </div>
  
</template>

<script>
import DatiKa from './components/datika.vue'
export default {
  data() {
    return {
      // 试卷基础信息
      paper: {
        tName: 'CSS基础知识测试',
        tDesc: '本测试用于检测CSS基础知识掌握情况'
      },
      //题目,通过axios获取,可以直接添加数组
      questions: [],
      // 双向绑定答案
      answers: {}
    }
  },
  components:{
    //注册答题卡子组件
    DatiKa
  },
  created() {
    //获取题目数据方法
    this.fetchPaper()
  },
  methods: {
    //axios获取后台api接口
    async fetchPaper() {
      const { data: res } = await this.$http.get('/api/Home/GTY')
      if (res.status !== 200) return this.$message.error('数据请求失败')
      this.questions = res.data
      console.log(this.questions)
    },
    //提交答案方法
    //将答案格式转化成一个数组,其中有两个属性anid(对应的是题目的tid),daan(选择或输入的答案)
    submitAnswers() {
      const answersArray = []
      for (const [anid, daan] of Object.entries(this.answers)) {
        answersArray.push({ anid, daan })
      }
      console.log(answersArray)
    }
  }
}
</script>

创建一个答题卡子组件并在父组件注册

<DatiKa :questions="questions" :answers="answers"></DatiKa>
components:{
    DatiKa
  }

根据父组件传递的值渲染答题卡子组件

<template>
    <div class="answer-sheet">
      <div class="answer-sheet-header">答题卡</div>
      <div class="answer-sheet-content">
        <ul>
          <li 
          v-for="(question, index) in questions" 
          :key="question.tid" 
          :class="{ 'answered': answers[question.tid] !== undefined && answers[question.tid].length > 0 }" 
          @click="scrollToQuestion(index)">
            {{ index + 1 }}
          </li>
        </ul>
      </div>
    </div>
  </template>
<script>
  export default {
    props: {
      questions: {
        type: Array,
        default: () => []
      },
      answers: {
        type: Object,
        default: () => ({})
      }
    },
    methods: {
      scrollToQuestion(index) {
        const questionEl = document.getElementById(`question-${index}`)
        if (questionEl) {
          questionEl.scrollIntoView({ behavior: 'smooth' })
        }
      }
    }
  }
  </script>
<style scoped>
  .answer-sheet {
    position: fixed;
    top: 20px;
    right: 20px;
    border: 1px solid #ddd;
    background-color: #fff;
    padding: 10px;
    border-radius: 4px;
  }
  
  .answer-sheet-header {
    font-weight: bold;
    margin-bottom: 10px;
  }
  
  .answer-sheet-content {
    max-height: 400px;
    overflow: auto;
  }
  
  .answer-sheet-content ul {
    list-style: none;
    padding: 0;
    margin: 0;
  }
  
  .answer-sheet-content ul li {
    display: inline-block;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    text-align: center;
    line-height: 30px;
    margin-right: 10px;
    margin-bottom: 10px;
    cursor: pointer;
  }

api返回的题目数据示例

{
  "status": 200,
  "data": [
    {
      "tid": 1,
      "tExplain": "下列css属性中,用于指定背景图片的是( )",
      "tScore": 25,
      "tType": 4,
      "tSort": 1,
      "tAnswer": "A,B,C,D",
      "tpaperId": 1,
      "topicSelect": [
        {
          "tselect": "A",
          "topics": "background-image"
        },
        {
          "tselect": "B",
          "topics": "background-color"
        },
        {
          "tselect": "C",
          "topics": "background-position"
        },
        {
          "tselect": "D",
          "topics": "background-repeat"
        }
      ]
    },
    {
      "tid": 2,
      "tExplain": "下面哪个CSS属性是用来改变背景颜色( )",
      "tScore": 25,
      "tType": 1,
      "tSort": 1,
      "tAnswer": "A",
      "tpaperId": 1,
      "topicSelect": [
        {
          "tselect": "A",
          "topics": "background-color"
        },
        {
          "tselect": "B",
          "topics": "bgcolor"
        },
        {
          "tselect": "C",
          "topics": "color"
        },
        {
          "tselect": "D",
          "topics": "text"
        }
      ]
    },
    {
      "tid": 3,
      "tExplain": "天空是红色的",
      "tScore": 25,
      "tType": 2,
      "tSort": 2,
      "tAnswer": "0",
      "tpaperId": 1,
      "topicSelect": [
        {
          "tselect": "A",
          "topics": ""
        },
        {
          "tselect": "B",
          "topics": ""
        },
        {
          "tselect": "C",
          "topics": ""
        },
        {
          "tselect": "D",
          "topics": ""
        }
      ]
    },
    {
      "tid": 4,
      "tExplain": "无序列表的标签是?",
      "tScore": 25,
      "tType": 3,
      "tSort": 3,
      "tAnswer": "<ul><li>",
      "tpaperId": 1,
      "topicSelect": [
        {
          "tselect": "A",
          "topics": ""
        },
        {
          "tselect": "B",
          "topics": ""
        },
        {
          "tselect": "C",
          "topics": ""
        },
        {
          "tselect": "D",
          "topics": ""
        }
      ]
    },
    {
      "tid": 5,
      "tExplain": "在C#.NET中,下列定义常量的语句中,正确的是( )",
      "tScore": 25,
      "tType": 1,
      "tSort": 1,
      "tAnswer": "B",
      "tpaperId": 2,
      "topicSelect": [
        {
          "tselect": "A",
          "topics": "const double PI 3.1415926;"
        },
        {
          "tselect": "B",
          "topics": "const double e=2.7;"
        },
        {
          "tselect": "C",
          "topics": "define double PI 3.1415926"
        },
        {
          "tselect": "D",
          "topics": "define double e=2.7"
        }
      ]
    },
    {
      "tid": 6,
      "tExplain": "在C#.NET中,下列变量名是正确的选项是( )",
      "tScore": 25,
      "tType": 1,
      "tSort": 1,
      "tAnswer": "C",
      "tpaperId": 2,
      "topicSelect": [
        {
          "tselect": "A",
          "topics": "$3"
        },
        {
          "tselect": "B",
          "topics": "45b"
        },
        {
          "tselect": "C",
          "topics": "a_3"
        },
        {
          "tselect": "D",
          "topics": "int"
        }
      ]
    },
    {
      "tid": 7,
      "tExplain": "C#源程序的扩展名是.cs",
      "tScore": 25,
      "tType": 2,
      "tSort": 2,
      "tAnswer": "1",
      "tpaperId": 2,
      "topicSelect": [
        {
          "tselect": "A",
          "topics": ""
        },
        {
          "tselect": "B",
          "topics": ""
        },
        {
          "tselect": "C",
          "topics": ""
        },
        {
          "tselect": "D",
          "topics": ""
        }
      ]
    },
    {
      "tid": 8,
      "tExplain": "在C#.NET中,设int a=3,b=4,c=5;表达式(a+b)>c&&b==c的值是:",
      "tScore": 25,
      "tType": 3,
      "tSort": 3,
      "tAnswer": "false",
      "tpaperId": 2,
      "topicSelect": [
        {
          "tselect": "A",
          "topics": ""
        },
        {
          "tselect": "B",
          "topics": ""
        },
        {
          "tselect": "C",
          "topics": ""
        },
        {
          "tselect": "D",
          "topics": ""
        }
      ]
    }
  ],
  "msg": "查询成功"
}

最后的效果展示

使用vue+element ui完成的考试测试功能Demo,vue,elementui,Powered by 金山文档

文章来源地址https://www.toymoban.com/news/detail-728725.html

到了这里,关于使用vue+element ui完成的考试测试功能Demo的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • vue使用element-ui实现分页功能

    element-ui官网上有分页实现的功能,简单方便又好用,也有很多分页的样式,你可以根据需要去选择自己想要的样式。这里讲的是完整功能样式的一个分页实现。过程如下: 分页方法完成。

    2024年02月13日
    浏览(33)
  • Vue+Element UI完成新建调查问卷

    先看看效果图: 添加填空题:  添加单选题、多选题: 对新增的题目可以上移、下移、编辑、删除操作:  效果大致就是这样,实现代码:    

    2024年02月11日
    浏览(28)
  • vue+element ui 完成 树形数据穿梭框

    element ui中的穿梭框只能实现平铺数据的穿梭,这次的需求是要树形数据穿梭,所以写的是tree组件自己组合的穿梭框

    2024年02月15日
    浏览(32)
  • 基于Vue+Element UI的文件管理系统-Demo

    记录一下之前写过的一个文件管理系统demo。 功能包括文件夹的新增、删除、重命名及移动,文件的上传、删除、移动及下载功能。 相关功能的操作直接和 后端 进行 请求 交互。 因为该demo集成在大的系统中,懒得提取建库开源,所以算是只记录思路。 右键文件夹时显示操作

    2024年03月08日
    浏览(27)
  • 使用 Vue 3.0 和 Element UI 实现功能增加和按钮操作详解

    简介: 在现代前端开发中,使用 Vue 3.0 和 Element UI 可以快速构建出功能强大、用户友好的界面。本篇技术博客将介绍如何结合 Vue 3.0 和 Element UI,实现功能增加和按钮操作的具体步骤和技巧。 首先,确保已经正确安装了 Vue 3.0 和 Element UI。可以通过 npm 或 yarn 进行安装,并在

    2024年02月04日
    浏览(29)
  • vue+element UI 使用el-cascader实现全选功能

    实现效果图     使用el-cascader代码片段 js代码 data数据设置: // 这里是处理成自己需要的数据格式, 需要把全选的这一选项过滤掉 // 原始选择的数据格式 [[\\\'全选\\\'], [1, 2], [1, 3], [1, 4],[5, 6], [5, 7, 8],5, 7, 9],[10]] //因为我自己需要的数据是“2,3,4,5”的格式,做了以下处理 注:本文是

    2024年02月12日
    浏览(42)
  • 使用element-ui+vue 做修改功能时,数据不回显问题

    后端数据已经做好了,页面发送数据获取id给后端,查询数据后返回给前段页面。res.data.data数据是可以打印出来的,但是这个_this.from一直打印出来的是undefined,找了很多方式都没有办法把值附上去。请问有什么办法吗 这个是表单页面

    2024年02月16日
    浏览(31)
  • 使用 Vue 3.0 和 Element UI 实现编辑功能、按钮操作和与后端接口交互的详解

    简介: Vue 3.0 和 Element UI 是当前流行的前端开发工具,结合它们可以轻松构建出强大的用户界面。本篇技术博客将详细介绍如何利用 Vue 3.0 和 Element UI 实现编辑功能、按钮操作以及与后端接口进行交互的具体步骤和技巧。 首先,确保已经正确安装了 Vue 3.0 和 Element UI。你可以

    2024年02月07日
    浏览(38)
  • 使用 Vue 3.0 和 Element UI 实现删除功能、按钮操作和基于查询框的信息查询详解

    简介: Vue 3.0 和 Element UI 是目前广泛应用于前端开发的工具,它们提供了丰富的组件和功能,可以帮助我们构建出强大的用户界面。本篇技术博客将详细介绍如何使用 Vue 3.0 和 Element UI 实现删除功能、按钮操作以及通过查询框输入信息进行信息查询的具体步骤和技巧。 首先,

    2024年02月03日
    浏览(34)
  • 简版的富文本编辑器、VUE+ElementUI 富文本编辑器 element ui富文本编辑器的使用(quill-editor) 不好用你来打我!全网醉简单!要复杂的别来!

    实现效果   1.安装插件 npm install vue-quill-editor --save 2.安装成功后在package.json中查看 3.在main.js中全局引入插件 4.页面实现 感谢老哥: ElementUI生成富文本编辑器 https://blog.csdn.net/keplerm/article/details/123379511?spm=1001.2101.3001.6650.9utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCom

    2024年02月16日
    浏览(55)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包