• Fab 悬浮按钮

    Fab 悬浮按钮

    悬浮按钮 fab button ,点击可展开一个图形按钮菜单。

    属性说明:

    属性名类型默认值说明
    patternobject可选样式配置项
    horizontalstring'left'水平对齐方式。left:左对齐,right:右对齐
    verticalstring'bottom'水平对齐方式。bottom:下对齐,top:上对齐
    directionstring'horizontal'展开菜单显示方式。horizontal:水平显示,vertical:垂直显示
    contentarray展开菜单内容配置项
    triggerfunction展开菜单点击事件,返回点击信息

    pattern配置项:

    参数类型默认值说明
    colorstring#3c3e49文字默认颜色
    selectedColorstring#007AFF文字选中时的颜色
    backgroundColorstring#ffffff背景色
    buttonColorstring#3c3e49按钮背景色

    content配置项:

    参数类型说明
    iconPathstring图片路径
    selectedIconPathstring选中后图片路径
    textstring文字
    activeboolean是否选中当前

    使用方法:

    template 中使用

    1. <template>
    2. <view>
    3. <uni-fab
    4. :pattern="pattern"
    5. :content="content"
    6. :horizontal="horizontal"
    7. :vertical="vertical"
    8. :direction="direction"
    9. @trigger="trigger"
    10. ></uni-fab>
    11. </view>
    12. </template>

    javascript 中使用

    1. import uniFab from '@/components/uni-fab.vue';
    2. export default {
    3. data() {
    4. return {
    5. horizontal: 'left',
    6. vertical: 'bottom',
    7. direction: 'horizontal',
    8. pattern: {
    9. color: '#7A7E83',
    10. backgroundColor: '#fff',
    11. selectedColor: '#007AFF',
    12. buttonColor:"#007AFF"
    13. },
    14. content: [
    15. {
    16. iconPath: '/static/component.png',
    17. selectedIconPath: '/static/componentHL.png',
    18. text: '组件',
    19. active: false
    20. },
    21. {
    22. iconPath: '/static/api.png',
    23. selectedIconPath: '/static/apiHL.png',
    24. text: 'API',
    25. active: false
    26. },
    27. {
    28. iconPath: '/static/template.png',
    29. selectedIconPath: '/static/templateHL.png',
    30. text: '模版',
    31. active: false
    32. }
    33. ]
    34. };
    35. },
    36. methods: {
    37. trigger(e) {
    38. console.log(e);
    39. this.content[e.index].active = !e.item.active;
    40. uni.showModal({
    41. title: '提示',
    42. content: `您${this.content[e.index].active?'选中了':'取消了'}${e.item.text}`,
    43. success: function(res) {
    44. if (res.confirm) {
    45. console.log('用户点击确定');
    46. } else if (res.cancel) {
    47. console.log('用户点击取消');
    48. }
    49. }
    50. });
    51. }
    52. },
    53. components: {
    54. uniFab
    55. }
    56. };

    Tips:

    • 不建议动态修改属性,可能会有影响。
    • 展开菜单暂不支持字体图标,使用图片路径时建议使用绝对路径,相对路径可能会有问题。
    • 选中状态要通过自己控制,如果不希望有选中状态,不处理 active 即可。
    • 展开菜单建议最多显示四个,如果过多对于小屏手机可能会超出屏幕。