我正在开发一个调查模块。我使用 Vue.js,我想知道如何在 Vue 中使用 javascript 生成器。
设想
场景如下,调查的问题和答案存储在mysql数据库中。我用 Axios 调用这个数据库,以便问题和答案存储在变量 response.data 中。
预期行为
我的目标是使用生成器函数显示单个问题及其答案选择,然后单击按钮显示下一个问题及其答案。
对于定向,最终结果在功能上应类似于以下来自 hotjar 的反馈民意调查: https: //www.hotjar.com/feedback-polls/
代码
Vue.component("frage", {
props: ["frage"],
template: "<h3> {{ frage }} </h3>",
});
let app = new Vue({
el: "#app",
data: {
auswahl: [],
picked: [],
fragen: [],
antworten: [],
frage: [],
count: 0,
pool: [],
gen: [],
},
mounted: function () {
this.getAllFragen();
this.gene();
},
methods: {
Addcount: function () {
console.log(this.fragen[this.count].quest);
this.count += 1;
let auswahl = this.fragen[this.count];
this.frage = …
Run Code Online (Sandbox Code Playgroud)我有一个表单,当我在其中输入数据并提交时,我将数据发送到reducer,然后将其保存到SQL 数据库。数据库返回我输入的数据和 ID,并将其存储在我的商店中。
现在我有另一个 React-Select 组件,我希望它将输入的数据显示为DefaultValue
.
我正在寻找一种方法,让 React 选择组件在从挂钩返回真值时重新加载useSelector
,最好是在该值发生变化时重新加载。
import React, { useEffect } from 'react';
import Select from 'react-select';
import { useDispatch, useSelector } from 'react-redux';
import {
getSelectOptions,
getOptions,
setSelectionValue,
getBookOptions,
} from '../store/selectReducer';
export default function selectForm() {
const dispatch = useDispatch();
useEffect(() => {
dispatch(getSelectOptions());
}, []);
const autoren = useSelector(getOptions).autorOpts;
//>>>>>>>>>>>>>> Here I retrieve the desired data from the store <<<<<<<<<<<<<<<<<<<<<<
const DEFAULTVALUE = useSelector(store => store.authorBook.author);
const onChangeAut = option …
Run Code Online (Sandbox Code Playgroud)