首页 > 解决方案 > 在vue js中随机播放对象的对象

问题描述

我想随机排列测验的每个问题的答案

[{"answers 1":"9 s 58","answer2":"9 s 72","answer3":"8 s 42","answer4":"8 s 36"},{"answer1":"Ottawa","answer2":"Toronto","answer3":"Montréal","answer4":"Québec"},{"answer1":"Mathilde","answer2":"Elizabeth","answer3":"Fabiola","answer4":"Paola"}]

我使用lodash的shuffle方法

import shuffle from 'lodash/shuffle';
export default {
    mounted() {
        this.$axios
            .get("http://localhost:4000/api/answers/" + this.$route.params.idQuiz)
            .then((response) => {
                this.reponses = response.data;
                for (var question in this.reponses){
                    shuffle(this.reponses[question])
                }
                console.log(this.reponses);
            })
            .catch((error) => {
                console.log(error);
            }),

标签: javascriptvue.jsrandomvuejs2shuffle

解决方案


推荐阅读