uni-app print()与console.log()区别

本文介绍了uni-app开发中常用的日志打印工具,包括console.log()、clogvar以及varcw的使用,重点阐述了它们的区别,如clogvar能显示变量名。此外,还提到了uni-app的打印功能会唤起打印页面。
uni-app在开发调试过程中,log是必不可少的
clog:输出:“console.log()”
clogvar:增强的日志输出,可同时把变量的名字打印出来
varcw:输出:“var currentWebview = this.mp.page.mp.page.mp.page.getAppWebview()”

而打印则会调出打印页面


更多详解:
喜欢可以加@群号:913934649

简书: https://www.jianshu.com/u/88db5f15770d

csdn:https://me.youkuaiyun.com/beyondforme

掘金:https://juejin.im/user/5e09a9e86fb9a016271294a7

<template> <div id="office-container" :class="`onlyoffice-app-` + fileType" :style="onlyOfficeStyle"> <div id="editor" ref="editor"></div> </div> </template> <script setup> import { getOnlyOfficeToken } from '@/common/ts/api/wwApi' import { defineComponent, ref, onMounted, onUnmounted } from 'vue'; import { onLoad } from '@dcloudio/uni-app'; import { useRoute } from 'vue-router' const editor = ref(null); let docEditor = null; let openUrl = '' let fileType = '' const route = useRoute() onLoad((options) => { if (options.openUrl) { openUrl = decodeURIComponent(options.openUrl); fileType = openUrl.split(".").pop().toLowerCase() console.log('接收到的 openUrl:', openUrl); } }); // 生命周期钩子 onMounted(() => { openUrl = decodeURIComponent(route.query.openUrl); console.log(`🚀 ~ initOnlyOffice ~ config.document.openUrl.split(".").pop():`, openUrl.split(".").pop()) fileType = openUrl.split(".").pop().toLowerCase() console.log("🚀 ~ onMounted ~ fileType:", fileType) const script = document.createElement('script'); const onlyOfficeUrl = import.meta.env.VITE_ONLY_OFFICE_SERVER; script.type = 'text/javascript'; script.src = `${onlyOfficeUrl}/web-apps/apps/api/documents/api.js?preload=placeholder`; script.onload = () => { if (openUrl) { loadDocumentFromUrl(openUrl); // loadDocumentFromUrl('http://dfs.dev.rosino.com:9000/cm-rsri/20250801/d6b3b2cf92e64a81a6f2c8013acafc3c-走访思考总结模板.xlsx'); // loadDocumentFromUrl('https://mzy-outernet-dev.rosino.com/out/file/biz-mit/public/20250806/c9ee802a7ef94ae59a9121dae112eb33.xlsm'); } }; script.onerror = (err) => { console.log("🚀 ~ onMounted ~ err:", err) }; document.head.appendChild(script); }); const getFileNameFromUrl = (url) => { return url.substring(url.lastIndexOf("/") + 1); }; const loadDocumentFromUrl = (fileUrl) => { if (!fileUrl || !fileUrl.trim()) { console.log("文件URL不能为空", "error"); return; } initOnlyOffice(fileUrl); }; const initOnlyOffice = async (fileUrl) => { const fileNameFromUrl = getFileNameFromUrl(fileUrl); try { if (docEditor) docEditor.destroyEditor(); } catch (error) { console.log("error: ", error); } console.log(`🚀 ~ initOnlyOffice ~ config.document.fileUrl.split(".").pop():`, fileUrl.split(".").pop()) let config = { type: "embedded", document: { title: fileNameFromUrl, url: fileUrl, protected: true, fileType: `${fileUrl.split(".").pop()}`, key: `doc_${Date.now()}_${Math.random()}`, permissions: { download: false, print: false, comment: false, copy: false, modifyFilter: false, modifyContentControl: false, edit: false, review: false, protectScheme: true, }, }, editorConfig: { lang: "zh-CN", mode: "view", deviceType: null, canEdit: false, customization: { allowEditRange: false, enableSheetProtection: true }, canCoAuthoring: false, user: { id: "anonymous", name: "Anonymous", }, coEditing: { mode: "fast", change: false, }, permissions: { download: false, print: false, chat: false, // 正确的设置位置 select: false, copy: false }, customization: { about: false, compactToolbar: true, help: false, feedback: false, goback: false, comments: false, select: false, forcesave: false, copy: false, // zoom: 50 }, }, events: { onDocumentReady: function () { console.log("文档加载完成"); docEditor.showMessage("文档加载完成", 3000); // docEditor.refreshFile(); // uni.showToast({ // title: '文档加载完成', // duration: 2000 // }); // if (iframe.contentDocument) { // iframeDoc = iframe.contentDocument; // } else if (iframe.contentWindow) { // iframeDoc = iframe.contentWindow.document; // } // console.log('iframeDoc:', iframeDoc) // const zoomIn = iframeDoc.querySelector('#id-btn-zoom-in'); // if (zoomIn) { // zoomIn.click(); // } } } }; let token = await getToken(config); config = { ...config, token: token.data }; try { docEditor = new DocsAPI.DocEditor("editor", config); } catch (error) { setTimeout(() => { initOnlyOffice(fileUrl); }, 1500); } }; // 获取token const getToken = async (data) => { let result = await getOnlyOfficeToken(encodeURIComponent(JSON.stringify(data))); return result; }; onUnmounted(() => { if (docEditor) { docEditor.destroyEditor(); } }); </script> <style scoped> #office-container { width: 100%; height: 100%; margin: 0; padding: 0; } #editor { width: 100%; height: 100%; min-height: 50px; /* 确保移动端滑动体验 */ -webkit-overflow-scrolling: touch; touch-action: pan-y; overflow: auto; } #toolbar { padding: 10px !important; display: none !important; } .onlyoffice-app-xlsx, .onlyoffice-app-xls, .onlyoffice-app-xlsm { margin-top: -28px !important; /* margin-left: -39px !important; width: calc(100% + 42px) !important; */ height: calc(100vh + 28px) !important; } .onlyoffice-app-ppt, .onlyoffice-app-pptx { margin-top: -28px !important; /* margin-left: -45px !important; width: calc(100% + 42px) !important; */ height: calc(100vh + 28px) !important; } .onlyoffice-app-pdf { margin-top: -28px !important; /* margin-left: -52px !important; width: calc(100% + 52px) !important; */ height: calc(100vh + 28px) !important; } .onlyoffice-app-doc, .onlyoffice-app-docx { margin-top: -28px !important; /* margin-left: -55px !important; width: calc(100% + 55px) !important; */ height: calc(100vh + 28px) !important; } .onlyoffice-app-txt { margin-top: -28px !important; /* margin-left: -55px !important; width: calc(100% + 55px) !important; */ height: calc(100vh + 28px) !important; } </style>在当前组件内,对PDF文件使用npm install vue进行预览,在当前文件修改,返回我完整代码
最新发布
01-06
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值