vue.js - Vue 调查幻灯片
问题描述
我正在做这样的调查:https ://takecareof.com/survey/new using vue。到目前为止,我有这个:
<template>
<div>
<div class="col-md-4 col-centered">
<div v-on:click="click()" class="survey-button"><slot></slot></div>
</div>
</div>
</template>
<script>
export default {
props: {
answer: {
type: String,
default: null,
}
},
data() {
return {
name: 'taest',
show: true,
}
},
methods: {
click() {
this.$parent.show = false;
//console.log('Question: ' + this.$parent.quesiton);
console.log('Quesiton: ' + this.$parent.getQuestion());
console.log('Answer: ' + this.answer);
console.log('Index: ' + this.$parent.getIndex());
}
}
}
</script>
<template>
<div class="row survey-question" v-show="show">
<h1><slot></slot></h1>
</div>
</template>
<script>
export default {
props: {
question: {
type: String,
default: null,
},
index: {
default: null,
}
},
data() {
return {
name: 'parent',
show: true,
}
},
methods: {
getQuestion() {
return this.question;
},
getIndex() {
return this.index;
}
},
}
</script>
<style>
.survey-question {
padding-top: 8em;
text-align: center;
}
</style>
<div id="app">
<surveyquestion question="how_often" index="0">
Which one best describes you?
<div class="col-md-offset-3">
<surveybutton answer="every_week">I train every week</surveybutton>
<surveybutton answer="some_weeks">I train some weeks</surveybutton>
</div>
</surveyquestion>
<surveyquestion question="where_train" index="1">
Which best describes you?
<surveybutton answer="one_location">I train in one location</surveybutton>
<surveybutton answer="mult_locations">I train in multiple locations</surveybutton>
<surveybutton answer="want_mult_locations">I would like to be able to train in more than one location.</surveybutton>
</surveyquestion>
<surveyquestion question="how_travel" index="2">
Which one best describes you?
<surveybutton answer="between_cities">I travel between cities for work</surveybutton>
<surveybutton answer="interstate">I travel interstate for work</surveybutton>
<surveybutton answer="suburbs">I travel between suburbs for work</surveybutton>
</surveyquestion>
</div>
</div>
我不确定如何隐藏一个调查问题并显示下一个?我想这样做是为了方便插入新问题,而我只是难以隐藏和显示新问题。在代码中,有两个组件。第一个是调查按钮,下一个是调查问题。我只是把它们砸在一起。我是 StackOverflow 的新手。有什么建议么?
解决方案
this.$children
您可以通过定义步骤 from和 a来充当根元素中的向导current_index
。show = true
然后仅显示current_index 处的子组件 ( )。
On click
,surveybutton
发出一个next
事件,该事件递增current_index
推荐阅读
- vue.js - 使用 DxSwitch 自定义 Vue DevExtreme 单元格
- php - 如何更改从 send::mail 保存到 DB 中的内容 - “Laravel 5.6”
- android - 协助使用 Android Studio WebView
- reactjs - 部署时的 Gh 页面未使用 React 呈现 src 或公用文件夹
- java - 当前方法“evaluatePostfix”正在运行但打印出错误结果(java)
- python-3.x - Alembic env.py 导入错误:ModuleNotFoundError: 'socket
- stata - 通过另一个变量以双向方式对面板重新排序,by() 图表
- python - python:RuntimeError: 没有正在运行的事件循环
- c# - 问题解析日期显示不正确的日期
- kivy - 获取 GLSL 顶点着色器位置以用于 cpu 事件碰撞器函数