Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

form组件内嵌space组件,space和其中的内容不渲染 #1609

Open
wthvosk opened this issue Apr 30, 2024 · 6 comments
Open

form组件内嵌space组件,space和其中的内容不渲染 #1609

wthvosk opened this issue Apr 30, 2024 · 6 comments
Labels
need reproduction Need reproduction

Comments

@wthvosk
Copy link

wthvosk commented Apr 30, 2024

Bug report 🐞

同标题,在开发环境下一切正常,打包部署后和其中的内容不渲染,换成div用flex gap就可以,已知:

  1. 组件确认有被正确引用和打包,单独使用没有问题。
  2. 没有更改过这两个组件的样式。

Version & Environment

node 20.11.1
"vue": "3.3.4",
"@varlet/ui": "3.2.4",
"vite": "4.4.8"

Expectation

开发环境
a1

Actual results (or Errors)

打包上生产环境,无了
a2

@haoziqaq
Copy link
Member

没能复现这个问题,需要提供一下最小化的可复现 demo。

@haoziqaq haoziqaq added the need reproduction Need reproduction label Apr 30, 2024
@wthvosk
Copy link
Author

wthvosk commented May 6, 2024

找到问题了,是表单内传给input的验证规则引起的

<var-input
                        v-model="model.username"
                        :placeholder="$t('page.login.common.userNamePlaceholder')"
                        :rules="new Rules().required().value"
                        size="small"
                        variant="outlined"
                    >
                        <template #prepend-icon>
                            <var-icon name="account-circle"/>
                        </template>
                    </var-input>
export class Rules {
    rules = []

    get value() {
        return this.rules;
    }

    required(errorMessage = '不能为空') {
        this.rules.push((v) => {
            if (v === null || v === undefined) return errorMessage;
            if (typeof v === 'string' && v.trim() === '') return errorMessage;
            if (Array.isArray(v) && v.length === 0) return errorMessage;
            if (typeof v === 'object' && !Array.isArray(v) && Object.keys(v).length === 0) return errorMessage;
            return true;
        });
        return this;
    }
}

@haoziqaq
Copy link
Member

haoziqaq commented May 6, 2024 via email

@wthvosk
Copy link
Author

wthvosk commented May 6, 2024

午休了,下午整一个

@wthvosk
Copy link
Author

wthvosk commented May 6, 2024

抱歉,水平有限,起新项目实在是复现不出来,总而言之换了种导出方式后问题解决了(还是一样,开发时正常,生产环境才出问题),可能是打包时类名压缩啥的出的问题,所以新项目不会出现。

class formRules{
    rules = []

    get value() {
        return this.rules;
    }

    required(errorMessage = '不能为空') {
        this.rules.push((v) => {
            if (v === null || v === undefined) return errorMessage;
            if (typeof v === 'string' && v.trim() === '') return errorMessage;
            if (Array.isArray(v) && v.length === 0) return errorMessage;
            if (typeof v === 'object' && !Array.isArray(v) && Object.keys(v).length === 0) return errorMessage;
            return true;
        });
        return this;
    }
}

export const Rules = new formRules();
<var-form ref="formRef">
        <var-space
            direction="column"
            size="5vmin"
        >
            <var-input
                v-model="model.username"
                :placeholder="$t('page.login.common.userNamePlaceholder')"
                :rules="Rules.required().value"
                size="small"
                variant="outlined"
                @keydown.enter="handleSubmit"
            >
                <template #prepend-icon>
                    <var-icon name="account-circle"/>
                </template>
            </var-input>
<var-input
                v-model="model.password"
                :placeholder="$t('page.login.common.passwordPlaceholder')"
                :rules="Rules.required().value"
                size="small"
                type="password"
                variant="outlined"
                @keydown.enter="handleSubmit"
            >
                <template #prepend-icon>
                    <var-icon name="lock"/>
                </template>
            </var-input>
</var-space>
</var-form>

@haoziqaq
Copy link
Member

haoziqaq commented May 6, 2024

这种现象很像是构建触发了 tree-shaking 导致部分代码被摇掉了。这个 issue 暂时开启一段时间,有问题可以留在这边。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need reproduction Need reproduction
Projects
None yet
Development

No branches or pull requests

2 participants