更新记录
2022.0608.0000(2022-06-08)
下载此版本
- 新增 props.selectedColor,选中时颜色配置
- 新增 props.onExceed,多选超出时钩子(默认会 toast 提示)
2022.0520.0000(2022-05-20)
下载此版本
平台兼容性
App |
快应用 |
微信小程序 |
支付宝小程序 |
百度小程序 |
字节小程序 |
QQ小程序 |
HBuilderX 3.1.0 |
× |
√ |
× |
× |
× |
× |
钉钉小程序 |
快手小程序 |
飞书小程序 |
京东小程序 |
鸿蒙元服务 |
× |
× |
× |
× |
× |
H5-Safari |
Android Browser |
微信浏览器(Android) |
QQ浏览器(Android) |
Chrome |
IE |
Edge |
Firefox |
PC-Safari |
× |
× |
× |
× |
√ |
× |
× |
× |
× |
zy-questionnaire
问卷生成
属性
属性名 |
类型 |
说明 |
默认值 |
items |
IItem[] |
列表项 |
[] |
selectedColor |
String |
选中颜色 |
'#93e600' |
onExceed |
(payload: { index: number; limit: number }) => void |
选项超出限制钩子, index 第几题, limit 限制数 |
|
interface IItemOption {
label: string;
value: string;
}
interface IItem {
question: string;
options: IItemOption[];
multiple?: boolean;
multipleLimit?: number;
}
插槽 slots
插槽名 |
说明 |
携带参数 |
default |
默认插槽,替换转盘项 |
{ question, options } |
- question |
题目插槽,默认插槽占用时无效 |
{ question, index } |
- option |
选项插槽,默认插槽占用时无效 |
{ option, index, selected } |
action |
操作插槽,替换按钮 |
{ answers } |
事件
事件名 |
说明 |
参数 |
submit |
提交数据 |
根据列表配置的对应选中值 |
样式说明
未使用 scoped
, 通过顶层样式名.zy-questionnaire
就可以进行调整。
使用案例
例1
<script setup lang="ts">
import ZyQuestionnaire from '@/uni_modules/zy-questionnaire/components/zy-questionnaire/zy-questionnaire.vue';
const props = {
items: [
{
question: '问题1?(单选)',
options: [{ label: '问1答1', value: '1-1' }, { label: '问1答2', value: '1-2' }, { label: '问1答3', value: '1-3' }, { label: '问1答4', value: '1-4' }]
},
{
question: '问题2?(多选)',
options: [
{ label: '问2答1', value: '2-1' },
{ label: '问2答2', value: '2-2' },
{ label: '问2答3', value: '2-3' },
{ label: '问2答4', value: '2-4' },
{ label: '问2答5', value: '2-5' },
{ label: '问2答6', value: '2-6' },
{ label: '问2答7', value: '2-7' }
],
multiple: true
},
{
question: '问题3?(多选:最多3项)',
options: [
{ label: '问3答1', value: '3-1' },
{ label: '问3答2', value: '3-2' },
{ label: '问3答3', value: '3-3' },
{ label: '问3答4', value: '3-4' },
{ label: '问3答5', value: '3-5' },
{ label: '问3答6', value: '3-6' },
{ label: '问3答7', value: '3-7' }
],
multipleLimit: 3
}
]
};
const handleSubmit = (answers: string[]) => {
console.log(answers)
}
</script>
<template>
<ZyQuestionnaire v-bind="props" @submit="handleSubmit" />
</template>
例2 (default)
默认插槽替换后,选项操作就需要自行处理了
<ZyQuestionnaire v-bind="props" @submit="handleSubmit">
<template #default="scope">
<view>问题: {{ scope.question }}</view>
<view>选项: {{ scope.options }}</view>
<hr />
</template>
</ZyQuestionnaire>
例3 (question)
<ZyQuestionnaire v-bind="props" @submit="handleSubmit">
<template #question="scope">
<view>问题插槽: {{ scope.index }} - {{ scope.question }}</view>
</template>
</ZyQuestionnaire>
例4 (option)
<ZyQuestionnaire v-bind="props" @submit="handleSubmit">
<template #option="scope">
{{ scope.selected }}
<view>选项插槽: {{ scope.index }} - {{ scope.option }}</view>
</template>
</ZyQuestionnaire>
例5 (action)
<ZyQuestionnaire v-bind="props" @submit="handleSubmit">
<template #action="scope">
action 插槽:{{ scope.answers }}
</template>
</ZyQuestionnaire>
意见反馈
有任何问题和建议,请通过评论进行留言。