reactjs - 类型“ChildNode”类型脚本上不存在属性“样式”
问题描述
我有一个像下面这样的代码。它工作得很好,但 TypeScript 告诉我:“ChildNode”类型脚本上不存在属性“样式”。这个错误
const allCoins = Array.from(document.querySelectorAll('li')))
const xs = !useMediaQuery(theme.breakpoints.down('xs'))
const md = !useMediaQuery(theme.breakpoints.down('sm'))
allCoins.map((coins) => {
if (coins.offsetHeight >= 53 && xs && !md) {
allCoins.map((coin) => {
coin.childNodes[0].childNodes[2].style.flex = '1 0 100%'
coin.childNodes[0].childNodes[2].style.marginLeft = '-3px'
})
} else {
allCoins.map((coin) => {
coin.childNodes[0].childNodes[2].style.flex = 'unset'
coin.childNodes[0].childNodes[2].style.marginLeft = '0'
})
}
})
我尝试了我在 Stack and Fit 上看到的所有解决方案,但没有一个适合我。
解决方案
这个解决方案对我来说很完美:)
const allCoins: HTMLElement[] = Array.from(document.querySelectorAll('li'))
const xs = !useMediaQuery(theme.breakpoints.down('xs'))
const md = !useMediaQuery(theme.breakpoints.down('sm'))
allCoins.map((coins) => {
if (coins.offsetHeight >= 53 && xs && !md) {
allCoins.map((coin) => {
(coin.childNodes[0].childNodes[2] as HTMLElement).style.flex = '1 0 100%';
(coin.childNodes[0].childNodes[2] as HTMLElement).style.marginLeft = '-3px';
})
} else {
allCoins.map((coin) => {
(coin.childNodes[0].childNodes[2] as HTMLElement).style.flex = 'unset';
(coin.childNodes[0].childNodes[2] as HTMLElement).style.marginLeft = '0';
})
}
})
推荐阅读
- apache-kafka - 无法配置 AWS Lambda 和 AWS Kafka(MSK 集群)之间的跨账户通信
- python - 质心跟踪,如何正确进行排序?
- json - Flutter andoid emulator 使用 path_provider 将文件保存到 Windows 本地磁盘在哪里?
- flutter - Flutter Web 项目不适用于托管
- node.js - 向 iOS 发送推送通知的问题,(云功能)
- bash - 回显名称不是数字,以防万一(选择)。#bash
- java - 对箭头文件进行零拷贝读取的 Java 方法?
- javascript - 文件上传开始时停止
- javascript - 在 EJS 中循环 JSON 以创建表
- c - 如何在 C 中输入输入运算符?