gpt4 book ai didi

javascript - 解开有关 javascript 的问题

转载 作者:行者123 更新时间:2023-12-02 21:53:49 24 4
gpt4 key购买 nike

我是 javascript 新手,我有一份调查代码,每次尝试都会打乱问题的顺序,我想停止该功能,但不知道如何停止。

这是我的容器上的代码

import React from 'react';
import QuestionPage from '../Pages/QuestionPage';
import axios from "axios";
import env from "../config/env";
import shuffle from 'shuffle-array';

class QuestionContainer extends React.Component {
constructor() {
super();
this.state = {
questions: []
};
this.SubmitQuestion = this.SubmitQuestion.bind(this);
}
componentDidMount() {

axios.get(`${env.url}/api/v1/en/questions?limit=100`).then((res) => {

let qes = shuffle(res.data.questions.map(a => ({
questionId: a.question_no,
question: a.question
})));
this.setState({ questions: qes });
}, (err) => {
console.log("Question fetch error ", err);
this.setState({questions:[{
questionId: 1,
question: 'All'}]})
});
}
SubmitQuestion(userAnswer){
axios.post(`${env.url}/api/v1/answer`,userAnswer).then((res) => {
console.log("Submitting success",res.data);
}, (err) => {
console.log("Submitting user answer ", err);

});
}
render() {
if(this.state.questions.length === 0 ) return null;
return (<QuestionPage SubmitQuestion={this.SubmitQuestion}
questions={this.state.questions} />);
}
}
export default QuestionContainer;

最佳答案

给你

import React from 'react';
import QuestionPage from '../Pages/QuestionPage';
import axios from "axios";
import env from "../config/env";

class QuestionContainer extends React.Component {
constructor() {
super();
this.state = {
questions: []
};
this.SubmitQuestion = this.SubmitQuestion.bind(this);
}
componentDidMount() {

axios.get(`${env.url}/api/v1/en/questions?limit=100`).then((res) => {
let qes = res.data.questions;
this.setState({ questions: qes });
}, (err) => {
console.log("Question fetch error ", err);
this.setState({questions:[{
questionId: 1,
question: 'All'}]})
});
}
SubmitQuestion(userAnswer){
axios.post(`${env.url}/api/v1/answer`,userAnswer).then((res) => {
console.log("Submitting success",res.data);
}, (err) => {
console.log("Submitting user answer ", err);

});
}
render() {
if(this.state.questions.length === 0 ) return null;
return (<QuestionPage SubmitQuestion={this.SubmitQuestion}
questions={this.state.questions} />);
}
}
export default QuestionContainer;

关于javascript - 解开有关 javascript 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60056792/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com