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

fix(qrcode): Fix the problem that the QR code cannot be dynamically generated #974

Merged
merged 2 commits into from
Jul 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions src/components/Qrcode/src/Qrcode.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
</div>
</template>
<script lang="ts">
import { defineComponent, watchEffect, PropType, ref, unref } from 'vue';
import { defineComponent, watch, PropType, ref, unref } from 'vue';
import { toCanvas, QRCodeRenderersOptions, LogoType } from './qrcodePlus';
import { toDataURL } from 'qrcode';
import { downloadByUrl } from '/@/utils/file/download';
Expand Down Expand Up @@ -93,11 +93,16 @@
});
}

watchEffect(() => {
setTimeout(() => {
createQrcode();
}, 30);
});
// 监听参数变化重新生成二维码
watch(
props,
() => {
createQrcode()
},
{
deep: true,
}
)

return { wrapRef, download };
},
Expand Down
10 changes: 9 additions & 1 deletion src/components/Qrcode/src/drawCanvas.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import { toCanvas } from 'qrcode';
import type { QRCodeRenderersOptions } from 'qrcode';
import { RenderQrCodeParams, ContentType } from './typing';
export const renderQrCode = ({ canvas, content, width = 0, options = {} }: RenderQrCodeParams) => {
import { cloneDeep } from 'lodash-es';

export const renderQrCode = ({
canvas,
content,
width = 0,
options: params = {}
}: RenderQrCodeParams) => {
const options = cloneDeep(params)
// 容错率,默认对内容少的二维码采用高容错率,内容多的二维码采用低容错率
options.errorCorrectionLevel = options.errorCorrectionLevel || getErrorCorrectionLevel(content);

Expand Down