账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    vue函数式组件中的render函数如何添加伪类样式
    34
    0

    问题描述

    export default {
        functional: true,
        props: {
            data: {
                type: String,
                default() {
                    return '';
                }
            },
            depth: {
                type: Number
            }
        },
        render: (h, ctx) => {
            return h('div', {
                class: ['treeitem'],
                style: {
                    ':hover': {
                        background: 'yellow'  // 希望在div这个元素上添加一个伪类的样式,但是没有效果
                    },
                    height: '40px',
                    lineHeight: '40px',
                    border: '1px solid #f0f0f0',
                    'marginLeft': ctx.props.depth*20 + 'px'
                },
                on: {
                    click: () => {
                    },
                    mouseover: () => {
                    }
                }
            }, [
                h('Icon', {
                    props: {
                        type: 'arrow-right-b',
                    },
                    style: {
                        marginLeft: '20px',
                        display: 'inline-block',
                        width: '40px',
                        hight: '40px'
                    }
                }),
                h('span',{
                    style: {
                    }
                }, ctx.props.data),
                h('Button', {
                    props: {
                        icon: 'ios-gear-outline'
                    },
                    style: {
                        float: 'right' 
                    },
                    on: {
                        click: () => {
                        }
                    }
                })
            ]);
        }
    }

    问题出现的环境背景及自己尝试过哪些方法

    尝试为div元素添加class,但是作为函数式组件,这个是js文件,style该写在哪里?

    相关代码

    // 请把代码文本粘贴到下方(请勿用图片代替代码)

    你期待的结果是什么?实际看到的错误信息又是什么?

    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • 石磨子 普通会员 1楼
      502 Bad Gateway

      502 Bad Gateway


      nginx
    更多回答
    网站公告
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部