vue 获取dom的css属性值

<template>
  <div id="topInfo" ref="topInfo" style="width: 200px;height: 200px;background-color: #0bb20c">
    <img id="imgInfo" ref="imgInfo" src="./20151205231902_xe2kG.jpeg" alt="" height="200px"  >
  </div>
</template>

<script>
    export default {
        name: "center",
      mounted() {
//div 标签获取的方法
        let topInfowidth = this.$refs.topInfo.style.width;
        let topInfoheight = this.$refs.topInfo.style.height;
        console.log("topInfo:"+topInfowidth+"  "+topInfoheight)

        console.log("=================================================")
//img 标签获取的方法
        let imgInfowidth = this.$refs.imgInfo.width;
        let imgInfoheight = this.$refs.imgInfo.height;
        console.log("imgInfo:"+imgInfowidth+"  "+imgInfoheight)
        let src = this.$refs.imgInfo.src;
        console.log("src:"+src)

      }   //获取dom元素高度通过在标签里面定义ref属性,用this.$refs.自定义名称.offsetHight;去获取。
    }
</script>

<style scoped>
  #topInfo{
  overflow: hidden;
}
</style>

注意:需要在mounted中才能获取到

  1. CSSStyleDeclaration {0: "width", 1: "height", 2: "background-color", 3: "padding-bottom", alignContent: "", alignItems: "", alignSelf: "", alignmentBaseline: "", all: "", …}
    1. alignContent:""
    2. alignItems:""
    3. alignSelf:""
    4. alignmentBaseline:""
    5. all:""
    6. animation:""
    7. animationDelay:""
    8. animationDirection:""
    9. animationDuration:""
    10. animationFillMode:""
    11. animationIterationCount:""
    12. animationName:""
    13. animationPlayState:""
    14. animationTimingFunction:""
    15. backdropFilter:""
    16. backfaceVisibility:""
    17. background:""
    18. backgroundAttachment:""
    19. backgroundBlendMode:""
    20. backgroundClip:""
    21. backgroundColor:"rgb(11, 178, 12)"
    22. backgroundImage:""
    23. backgroundOrigin:""
    24. backgroundPosition:""
    25. backgroundPositionX:""
    26. backgroundPositionY:""
    27. backgroundRepeat:""
    28. backgroundRepeatX:""
    29. backgroundRepeatY:""
    30. backgroundSize:""
    31. baselineShift:""
    32. blockSize:""
    33. border:""
    34. borderBottom:""
    35. borderBottomColor:""
    36. borderBottomLeftRadius:""
    37. borderBottomRightRadius:""
    38. borderBottomStyle:""
    39. borderBottomWidth:""
    40. borderCollapse:""
    41. borderColor:""
    42. borderImage:""
    43. borderImageOutset:""
    44. borderImageRepeat:""
    45. borderImageSlice:""
    46. borderImageSource:""
    47. borderImageWidth:""
    48. borderLeft:""
    49. borderLeftColor:""
    50. borderLeftStyle:""
    51. borderLeftWidth:""
    52. borderRadius:""
    53. borderRight:""
    54. borderRightColor:""
    55. borderRightStyle:""
    56. borderRightWidth:""
    57. borderSpacing:""
    58. borderStyle:""
    59. borderTop:""
    60. borderTopColor:""
    61. borderTopLeftRadius:""
    62. borderTopRightRadius:""
    63. borderTopStyle:""
    64. borderTopWidth:""
    65. borderWidth:""
    66. bottom:""
    67. boxShadow:""
    68. boxSizing:""
    69. breakAfter:""
    70. breakBefore:""
    71. breakInside:""
    72. bufferedRendering:""
    73. captionSide:""
    74. caretColor:""
    75. clear:""
    76. clip:""
    77. clipPath:""
    78. clipRule:""
    79. color:""
    80. colorInterpolation:""
    81. colorInterpolationFilters:""
    82. colorRendering:""
    83. columnCount:""
    84. columnFill:""
    85. columnGap:""
    86. columnRule:""
    87. columnRuleColor:""
    88. columnRuleStyle:""
    89. columnRuleWidth:""
    90. columnSpan:""
    91. columnWidth:""
    92. columns:""
    93. contain:""
    94. content:""
    95. counterIncrement:""
    96. counterReset:""
    97. cssFloat:""
    98. cssText:"width: 20px; height: 100px; background-color: rgb(11, 178, 12); padding-bottom: 55px;"
    99. cursor:""
    100. cx:""
    101. cy:""
    102. d:""
    103. direction:""
    104. display:""
    105. dominantBaseline:""
    106. emptyCells:""
    107. fill:""
    108. fillOpacity:""
    109. fillRule:""
    110. filter:""
    111. flex:""
    112. flexBasis:""
    113. flexDirection:""
    114. flexFlow:""
    115. flexGrow:""
    116. flexShrink:""
    117. flexWrap:""
    118. float:""
    119. floodColor:""
    120. floodOpacity:""
    121. font:""
    122. fontDisplay:""
    123. fontFamily:""
    124. fontFeatureSettings:""
    125. fontKerning:""
    126. fontSize:""
    127. fontSizeAdjust:""
    128. fontStretch:""
    129. fontStyle:""
    130. fontVariant:""
    131. fontVariantCaps:""
    132. fontVariantLigatures:""
    133. fontVariantNumeric:""
    134. fontVariationSettings:""
    135. fontWeight:""
    136. grid:""
    137. gridArea:""
    138. gridAutoColumns:""
    139. gridAutoFlow:""
    140. gridAutoRows:""
    141. gridColumn:""
    142. gridColumnEnd:""
    143. gridColumnGap:""
    144. gridColumnStart:""
    145. gridGap:""
    146. gridRow:""
    147. gridRowEnd:""
    148. gridRowGap:""
    149. gridRowStart:""
    150. gridTemplate:""
    151. gridTemplateAreas:""
    152. gridTemplateColumns:""
    153. gridTemplateRows:""
    154. height:"100px"
    155. hyphens:""
    156. imageRendering:""
    157. inlineSize:""
    158. isolation:""
    159. justifyContent:""
    160. justifyItems:""
    161. justifySelf:""
    162. left:""
    163. length:4
    164. letterSpacing:""
    165. lightingColor:""
    166. lineHeight:""
    167. lineHeightStep:""
    168. listStyle:""
    169. listStyleImage:""
    170. listStylePosition:""
    171. listStyleType:""
    172. margin:""
    173. marginBottom:""
    174. marginLeft:""
    175. marginRight:""
    176. marginTop:""
    177. marker:""
    178. markerEnd:""
    179. markerMid:""
    180. markerStart:""
    181. mask:""
    182. maskSourceType:""
    183. maskType:""
    184. maxBlockSize:""
    185. maxHeight:""
    186. maxInlineSize:""
    187. maxWidth:""
    188. maxZoom:""
    189. minBlockSize:""
    190. minHeight:""
    191. minInlineSize:""
    192. minWidth:""
    193. minZoom:""
    194. mixBlendMode:""
    195. objectFit:""
    196. objectPosition:""
    197. offset:""
    198. offsetAnchor:""
    199. offsetDistance:""
    200. offsetPath:""
    201. offsetPosition:""
    202. offsetRotate:""
    203. opacity:""
    204. order:""
    205. orientation:""
    206. orphans:""
    207. outline:""
    208. outlineColor:""
    209. outlineOffset:""
    210. outlineStyle:""
    211. outlineWidth:""
    212. overflow:""
    213. overflowAnchor:""
    214. overflowWrap:""
    215. overflowX:""
    216. overflowY:""
    217. padding:""
    218. paddingBottom:"55px"
    219. paddingLeft:""
    220. paddingRight:""
    221. paddingTop:""
    222. page:""
    223. pageBreakAfter:""
    224. pageBreakBefore:""
    225. pageBreakInside:""
    226. paintOrder:""
    227. parentRule:null
    228. perspective:""
    229. perspectiveOrigin:""
    230. placeContent:""
    231. placeItems:""
    232. placeSelf:""
    233. pointerEvents:""
    234. position:""
    235. quotes:""
    236. r:""
    237. resize:""
    238. right:""
    239. rotate:""
    240. rx:""
    241. ry:""
    242. scale:""
    243. scrollBehavior:""
    244. shapeImageThreshold:""
    245. shapeMargin:""
    246. shapeOutside:""
    247. shapeRendering:""
    248. size:""
    249. speak:""
    250. src:""
    251. stopColor:""
    252. stopOpacity:""
    253. stroke:""
    254. strokeDasharray:""
    255. strokeDashoffset:""
    256. strokeLinecap:""
    257. strokeLinejoin:""
    258. strokeMiterlimit:""
    259. strokeOpacity:""
    260. strokeWidth:""
    261. tabSize:""
    262. tableLayout:""
    263. textAlign:""
    264. textAlignLast:""
    265. textAnchor:""
    266. textCombineUpright:""
    267. textDecoration:""
    268. textDecorationColor:""
    269. textDecorationLine:""
    270. textDecorationSkip:""
    271. textDecorationStyle:""
    272. textIndent:""
    273. textJustify:""
    274. textOrientation:""
    275. textOverflow:""
    276. textRendering:""
    277. textShadow:""
    278. textSizeAdjust:""
    279. textTransform:""
    280. textUnderlinePosition:""
    281. top:""
    282. touchAction:""
    283. transform:""
    284. transformBox:""
    285. transformOrigin:""
    286. transformStyle:""
    287. transition:""
    288. transitionDelay:""
    289. transitionDuration:""
    290. transitionProperty:""
    291. transitionTimingFunction:""
    292. translate:""
    293. unicodeBidi:""
    294. unicodeRange:""
    295. userSelect:""
    296. userZoom:""
    297. vectorEffect:""
    298. verticalAlign:""
    299. visibility:""
    300. webkitAppRegion:""
    301. webkitAppearance:""
    302. webkitBackgroundClip:""
    303. webkitBackgroundOrigin:""
    304. webkitBorderAfter:""
    305. webkitBorderAfterColor:""
    306. webkitBorderAfterStyle:""
    307. webkitBorderAfterWidth:""
    308. webkitBorderBefore:""
    309. webkitBorderBeforeColor:""
    310. webkitBorderBeforeStyle:""
    311. webkitBorderBeforeWidth:""
    312. webkitBorderEnd:""
    313. webkitBorderEndColor:""
    314. webkitBorderEndStyle:""
    315. webkitBorderEndWidth:""
    316. webkitBorderHorizontalSpacing:""
    317. webkitBorderImage:""
    318. webkitBorderStart:""
    319. webkitBorderStartColor:""
    320. webkitBorderStartStyle:""
    321. webkitBorderStartWidth:""
    322. webkitBorderVerticalSpacing:""
    323. webkitBoxAlign:""
    324. webkitBoxDecorationBreak:""
    325. webkitBoxDirection:""
    326. webkitBoxFlex:""
    327. webkitBoxFlexGroup:""
    328. webkitBoxLines:""
    329. webkitBoxOrdinalGroup:""
    330. webkitBoxOrient:""
    331. webkitBoxPack:""
    332. webkitBoxReflect:""
    333. webkitColumnBreakAfter:""
    334. webkitColumnBreakBefore:""
    335. webkitColumnBreakInside:""
    336. webkitFontSizeDelta:""
    337. webkitFontSmoothing:""
    338. webkitHighlight:""
    339. webkitHyphenateCharacter:""
    340. webkitLineBreak:""
    341. webkitLineClamp:""
    342. webkitLocale:""
    343. webkitLogicalHeight:""
    344. webkitLogicalWidth:""
    345. webkitMarginAfter:""
    346. webkitMarginAfterCollapse:""
    347. webkitMarginBefore:""
    348. webkitMarginBeforeCollapse:""
    349. webkitMarginBottomCollapse:""
    350. webkitMarginCollapse:""
    351. webkitMarginEnd:""
    352. webkitMarginStart:""
    353. webkitMarginTopCollapse:""
    354. webkitMask:""
    355. webkitMaskBoxImage:""
    356. webkitMaskBoxImageOutset:""
    357. webkitMaskBoxImageRepeat:""
    358. webkitMaskBoxImageSlice:""
    359. webkitMaskBoxImageSource:""
    360. webkitMaskBoxImageWidth:""
    361. webkitMaskClip:""
    362. webkitMaskComposite:""
    363. webkitMaskImage:""
    364. webkitMaskOrigin:""
    365. webkitMaskPosition:""
    366. webkitMaskPositionX:""
    367. webkitMaskPositionY:""
    368. webkitMaskRepeat:""
    369. webkitMaskRepeatX:""
    370. webkitMaskRepeatY:""
    371. webkitMaskSize:""
    372. webkitMaxLogicalHeight:""
    373. webkitMaxLogicalWidth:""
    374. webkitMinLogicalHeight:""
    375. webkitMinLogicalWidth:""
    376. webkitPaddingAfter:""
    377. webkitPaddingBefore:""
    378. webkitPaddingEnd:""
    379. webkitPaddingStart:""
    380. webkitPerspectiveOriginX:""
    381. webkitPerspectiveOriginY:""
    382. webkitPrintColorAdjust:""
    383. webkitRtlOrdering:""
    384. webkitRubyPosition:""
    385. webkitTapHighlightColor:""
    386. webkitTextCombine:""
    387. webkitTextDecorationsInEffect:""
    388. webkitTextEmphasis:""
    389. webkitTextEmphasisColor:""
    390. webkitTextEmphasisPosition:""
    391. webkitTextEmphasisStyle:""
    392. webkitTextFillColor:""
    393. webkitTextOrientation:""
    394. webkitTextSecurity:""
    395. webkitTextStroke:""
    396. webkitTextStrokeColor:""
    397. webkitTextStrokeWidth:""
    398. webkitTransformOriginX:""
    399. webkitTransformOriginY:""
    400. webkitTransformOriginZ:""
    401. webkitUserDrag:""
    402. webkitUserModify:""
    403. webkitWritingMode:""
    404. whiteSpace:""
    405. widows:""
    406. width:"20px"
    407. willChange:""
    408. wordBreak:""
    409. wordSpacing:""
    410. wordWrap:""
    411. writingMode:""
    412. x:""
    413. y:""
    414. zIndex:""
    415. zoom:""
    416. 0:"width"
    417. 1:"height"
    418. 2:"background-color"
    419. 3:"padding-bottom"
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值