網站首頁 編程語言 正文
后端傳來的數據是數據0,1,2。0代表js報錯,1代表白屏,2代表其他錯誤,要求動態顯示在表格中
<el-table-column align="center" prop="errorText" label="異常類型" width="150">
<template slot-scope="{row: {errorText}}">
<span v-if="+errorText === 0">js報錯</span>
<span v-else-if="+errorText === 1">白屏</span>
<span v-else>其他錯誤</span>
</template>
</el-table-column>
知識點
slot-scope="{row: {errorText}}" 相當于用slot-scope="{data}"分解出該作用域里的errorText
,后面直接使用即可
+errorText,把errorText
轉為數字進行全等比較,不使用==是為了避免出錯,根據項目需求調整
參考:https://blog.csdn.net/weixin_42557996/article/details/95663194
2022.3.25更新:
CSDN現在這個文章質量提示真的很蛋疼,以前還是小白的時候隨手寫的一個插槽分享我還能碼多少字?現在回頭看發現了個寫錯的地方要改改還得加字數就離譜,隨便貼一串代碼吧,以下的可以不看
<template>
<div class="drag">
<div class="back_box" ref="back_box">
這是一個背景
<div
class="drag_box"
draggable="true"
@dragstart="dragstart"
@dragend="dragend"
@wheel="handleWeel"
:style="`left:${elLeft}px;top:${elTop}px;width:${elWidth}px;height:${elHeight}px;`"
>
<div
class="text"
:style="`left:${(0 * this.elWidth) / 100}px;top:${
(25 * this.elHeight) / 100
}px;-webkit-transform: scale(${meter_zoom} )`"
>
這是一個藍色可拖拽元素
</div>
</div>
</div>
</div>
</template>
<script>
export default {
name: "HelloWorld",
props: {
msg: String,
},
data() {
return {
initWidth: 0, // 父元素的寬-自適應值
initHeight: 0, // 父元素的高-自適應值
startclientX: 0, // 元素拖拽前距離瀏覽器的X軸位置
startclientY: 0, //元素拖拽前距離瀏覽器的Y軸位置
elLeft: 0, // 元素的左偏移量
elTop: 0, // 元素的右偏移量
zoom: 1, // 縮放比例
elWidth: 0, // 元素寬
elHeight: 0, // 元素高
meter_zoom: 0, // 子元素縮放比例
};
},
methods: {
// 頁面初始化
initBodySize() {
this.initWidth = this.$refs.back_box.clientWidth; // 拿到父元素寬
// this.initHeight = this.initWidth * (1080 / 1920);
this.initHeight = this.initWidth * ((1080 * 0.88) / (1920 - 1080 * 0.02)); // 根據寬計算高實現自適應
this.elWidth = this.initWidth * (100 / (1920 / 2));
this.elHeight = this.initHeight * (100 / (1080 / 2));
this.meter_zoom = this.elWidth / 100; // 計算子元素縮放比例
},
// 拖拽開始事件
dragstart(e) {
console.log(e);
this.startclientX = e.clientX; // 記錄拖拽元素初始位置
this.startclientY = e.clientY;
},
// 拖拽完成事件
dragend(e) {
console.log(e);
let x = e.clientX - this.startclientX; // 計算偏移量
let y = e.clientY - this.startclientY;
this.elLeft += x; // 實現拖拽元素隨偏移量移動
this.elTop += y;
},
// 滾輪放大縮小事件
handleWeel(e) {
console.log(e);
if (e.wheelDelta < 0) {
this.zoom -= 0.05;
} else {
this.zoom += 0.05;
}
if (this.zoom >= 3) {
this.zoom = 3;
return;
}
if (this.zoom <= 0.5) {
this.zoom = 0.5;
return;
}
this.elWidth = this.initWidth * (100 / (1920 / 2)) * this.zoom;
this.elHeight = this.initHeight * (100 / (1080 / 2)) * this.zoom;
this.meter_zoom = this.elWidth / 100;
},
},
mounted() {
// console.log(this.$el);
this.initBodySize();
},
};
</script>
<style scoped>
.back_box {
background: #ccc;
width: 50vw;
height: 50vh;
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -30%);
}
.drag_box {
width: 100px;
height: 100px;
background: skyblue;
position: absolute;
z-index: 10;
user-select: none; /* 不可選中,為了拖拽時不讓文字高亮 */
}
.text {
position: absolute;
width: 100px;
height: 100px;
transform-origin: 0 0; /* 用作縮放基點 */
font-size: 16px;
}
</style>
THX
原文鏈接:https://blog.csdn.net/vvv3171071/article/details/121467535
- 上一篇:沒有了
- 下一篇:沒有了
相關推薦
- 2022-12-04 React18?useState何時執行更新及微任務理解_React
- 2022-02-07 laravel生成二維碼/生成base64二維碼流、simple-qrcode擴展
- 2022-11-26 React常見跨窗口通信方式實例詳解_React
- 2022-06-12 C語言詳解熱門考點結構體內存對齊_C 語言
- 2022-07-17 Python中使用tkFileDialog實現文件選擇、保存和路徑選擇_python
- 2022-08-10 python中ThreadPoolExecutor線程池和ProcessPoolExecutor進程
- 2023-04-08 Swift中的HTTP模擬測試示例詳解_Swift
- 2022-06-16 C語言通過案例講解并發編程模型_C 語言
- 欄目分類
-
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支