S
S
SM_ST2022-04-01 22:08:11
JavaScript
SM_ST, 2022-04-01 22:08:11

How to output the width of each element from a list?

eat list

<div id="range" class="demo"> 
       <span v-for="n in 10"> 
              <span class="item">{{ n }}</span> 
       </span> 
</div>

how to calculate the width of each when drawing and if it is more than 150 then do not display the block

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alex Step, 2022-04-01
@kellas

This can only be done after rendering.
First you need to get links to these spans in js - https://v3.ru.vuejs.org/ru/guide/migration/array-r...
Instead of outputting from one to 10, make an array of objects, with a number and a show flag and iterates over this array
Then in the loop you iterate over them and see the width
this.$refs.items[0].clientWidth , change the show flag for the corresponding array element

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question