<el-col :span="24" style="padding-bottom: 3%"> <el-form-item elid="el_bd69260c" prop="wjzc" need> <wf-file ref="file" v-model="form.wjzc" show_header show_size show_user show_time :fixitems="[]" :autoBind="true"> </wf-file> </el-form-item> </el-col>改成view写法
时间: 2024-02-14 16:32:00 浏览: 190
<-col :span="24" style="padding-bottom: 3%">
<el-form-item elid="el_bd69260c" prop="wjzc" need>
<wf-file ref="file" v-model="form.wjzc" show_header show_size show_user show_time :fixitems="[]" :autoBind="true" disabled>
<template #default="{ value }">
<el-upload-list v-bind:value="value" type="picture-card">
<i class="el-icon-plus"></i>
</el-upload-list>
</template>
</wf-file>
</el-form-item>
</el-col>
相关问题
const print = () => { if (!baseInfo.orderCode) { message.error("打印正在准备,请5秒后再点击") return } const el = document.getElementById("print-container") const iframe = document.createElement("IFRAME") let doc = null // iframe.setAttribute('style', 'position:absolute;top:0px;left:0px;width:100%;height:100%',); document.body.appendChild(iframe) doc = iframe.contentWindow.document // 引入打印的专有CSS样式,根据实际修改 doc.write(`<LINK rel="stylesheet" type="text/css" href="./orderPrint.css">`) doc.write(el.innerHTML) doc.close() // 获取iframe的焦点,从iframe开始打印 iframe.contentWindow.focus() iframe.onload = () => { iframe.contentWindow.print() document.body.removeChild(iframe) } if (navigator.userAgent.indexOf("MSIE") > 0) { document.body.removeChild(iframe) } const old = window.document.body.innerHTML const printPart = document.getElementById("print-container") window.document.body.innerHTML = "" window.document.body.appendChild(printPart) window.print() window.document.body.innerHTML = old window.location.reload() }优化这段代码
这段代码可以进行如下的优化:
1. 避免在函数内部操作 DOM,最好将其作为参数传递进来,这样可以提高代码的可重用性和可维护性。
```javascript
const print = (elId, cssUrl) => {
const el = document.getElementById(elId)
if (!el) {
message.error("找不到打印内容,请检查elId")
return
}
if (!baseInfo.orderCode) {
message.error("打印正在准备,请5秒后再点击")
return
}
const iframe = document.createElement("IFRAME")
document.body.appendChild(iframe)
const doc = iframe.contentWindow.document
doc.write(`<LINK rel="stylesheet" type="text/css" href="${cssUrl}">`)
doc.write(el.innerHTML)
doc.close()
iframe.contentWindow.focus()
iframe.onload = () => {
iframe.contentWindow.print()
document.body.removeChild(iframe)
}
if (navigator.userAgent.indexOf("MSIE") > 0) {
document.body.removeChild(iframe)
}
}
```
2. 将打印的专有CSS样式和打印的内容分开处理,以便更好地维护和修改样式。
```javascript
const print = (elId, cssUrl, printContent) => {
const el = document.getElementById(elId)
if (!el) {
message.error("找不到打印内容,请检查elId")
return
}
if (!baseInfo.orderCode) {
message.error("打印正在准备,请5秒后再点击")
return
}
const iframe = document.createElement("IFRAME")
document.body.appendChild(iframe)
const doc = iframe.contentWindow.document
const link = document.createElement("link")
link.rel = "stylesheet"
link.type = "text/css"
link.href = cssUrl
doc.head.appendChild(link)
doc.body.innerHTML = printContent || el.innerHTML
iframe.contentWindow.focus()
iframe.onload = () => {
iframe.contentWindow.print()
document.body.removeChild(iframe)
}
if (navigator.userAgent.indexOf("MSIE") > 0) {
document.body.removeChild(iframe)
}
}
```
3. 将打印内容从 DOM 中分离出来,以便在不同的场合下方便地调用。
```javascript
const printContent = (elId) => {
const el = document.getElementById(elId)
if (!el) {
message.error("找不到打印内容,请检查elId")
return ""
}
return el.innerHTML
}
const print = (elId, cssUrl, printContent) => {
if (!baseInfo.orderCode) {
message.error("打印正在准备,请5秒后再点击")
return
}
const iframe = document.createElement("IFRAME")
document.body.appendChild(iframe)
const doc = iframe.contentWindow.document
const link = document.createElement("link")
link.rel = "stylesheet"
link.type = "text/css"
link.href = cssUrl
doc.head.appendChild(link)
doc.body.innerHTML = printContent || printContent(elId)
iframe.contentWindow.focus()
iframe.onload = () => {
iframe.contentWindow.print()
document.body.removeChild(iframe)
}
if (navigator.userAgent.indexOf("MSIE") > 0) {
document.body.removeChild(iframe)
}
}
```
[runtime not ready]: TypeError: Cannot read property 'style' of undefined, js engine: hermes Unhandled JS Exception: [runtime not ready]: TypeError: Cannot read property 'style' of undefined, js engine: hermes 'Failed to print error: ', 'Exception in HostFunction: <unknown>' [runtime not ready]: TypeError: Cannot read property 'style' of undefined, js engine: hermes
### Hermes JS 引擎运行时错误分析
当在使用 Hermes JavaScript 引擎时遇到 `TypeError: Cannot read property 'style' of undefined` 错误,这通常表明尝试访问的对象未被正确定义或初始化。以下是可能的原因以及解决方案:
#### 可能原因一:对象未定义
如果代码试图访问某个变量的属性(例如 `.style`),而该变量尚未声明或赋值,则会触发此错误。
```javascript
let element; // 声明但未初始化
console.log(element.style); // TypeError: Cannot read property 'style' of undefined
```
为了防止此类问题发生,在访问任何对象之前应验证其是否存在[^1]。
#### 解决方案一:检查并确认对象存在
通过条件语句来确保目标对象已被正确加载后再执行操作。
```javascript
if (element && typeof element === 'object') {
console.log(element.style);
} else {
console.error('Element is not defined or invalid.');
}
```
#### 可能原因二:DOM 元素获取失败
如果是前端开发场景下处理 HTML DOM 节点时出现问题,可能是由于未能成功检索到指定节点所致。
```javascript
const element = document.getElementById('nonexistentId');
console.log(element.style); // 如果找不到对应ID则返回undefined,进而抛出异常
```
在这种情况下,应该先核实所选元素确实存在于文档结构之中[^2]。
#### 解决方案二:增强选择器健壮性
采用更可靠的机制定位所需组件,并加入必要的错误捕获逻辑。
```javascript
function getElementByIdSafe(id) {
const el = document.getElementById(id);
if (!el || !(typeof el === 'object')) throw new Error(`No such element with id=${id}`);
return el;
}
try {
let safeEl = getElementByIdSafe('myValidElementId');
console.log(safeEl.style);
} catch(e){
console.error(e.message);
}
```
以上方法可以有效减少因意外丢失引用而导致的应用崩溃风险。
#### 性能优化建议
考虑到Hermes专注于提升React Native应用性能的特点,对于频繁使用的UI控件样式读写动作可考虑缓存策略以降低重复查询开销[^3]。
```javascript
class StyleCache{
constructor(){
this.cacheMap={};
}
getStyle(elId){
if(this.cacheMap[elId]){
return this.cacheMap[elId];
}else{
try{
var el=getElementByIdSafe(elId);
this.cacheMap[elId]=el.style;
return this.cacheMap[elId];
}catch(err){
console.warn(`Failed to cache style for ${elId}:`, err);
delete this.cacheMap[elId]; //清理潜在脏数据
return null;
}
}
}
}
```
阅读全文
相关推荐















