The questioner did not write the vue tag, but I saw the v-for instruction. The questioner should be asking how to use vue to arrange 1-10 in reverse order. Suppose there is the following vue component
var vm = new Vue({
el: '#app',
template: `
<ul>
<li v-for="item in arr">loop {{item}}</li>
</ul>
`,
filters: {
},
data() {
return {
arr:10,
}
},
})
1.Use filter
filters: {
sort(v) {
if (!v)
return ''
else {
return 11 - v
}
},
template:`<ul><li v-for="item in arr">{{item|sort}}</li></ul>`
2.Using vue method
template: `
<ul>
<li v-for="item in arr">{{reverseNumber(item)}}</li>
</ul>
`,
methods: {
reverseNumber(x) {
return 11 - x
},
}
There is no way to use calculated attributes to loop through a number like this. The calculated attribute is data中一个值改变后,把他映射到另外一个值相当于一个函数,而v-forwhich is equivalent to an iterator after looping through the list data, and does not change a certain attribute value of the data.
It is recommended that you loop an array or object instead of looping numbers directly. Unless the logic is really simple, it just generates several tags in a loop. To sort an array elements, you can also use sort() to pass in the reverse order function, so that you can use calculated properties. First map the sorted array to the calculated properties, and then loop through the calculated properties in reverse order. Reverse order can also be implemented. v-for
In simple cases, I recommend using filters, which are Angular pipelines
If you want to go from 10 to 1, wouldn’t it be enough to just
11 - n
...Why are you so upright...
The questioner did not write the vue tag, but I saw the v-for instruction. The questioner should be asking how to use vue to arrange 1-10 in reverse order.
Suppose there is the following vue component
1.Use filter
2.Using vue method
There is no way to use calculated attributes to loop through a number like this. The calculated attribute is
data
中一个值改变后,把他映射到另外一个值相当于一个函数,而v-for
which is equivalent to an iterator after looping through the list data, and does not change a certain attribute value of the data.It is recommended that you loop an array or object instead of looping numbers directly. Unless the logic is really simple, it just generates several tags in a loop. To sort an array elements, you can also use sort() to pass in the reverse order function, so that you can use calculated properties. First map the sorted array to the calculated properties, and then loop through the calculated properties in reverse order. Reverse order can also be implemented.
In simple cases, I recommend using filters, which are Angular pipelinesv-for
Then you need to build an array to store 10~1
You can use calculated attributes, see [Portal] for details, pass in the js sorting method sort, if you don’t understand sort, check it out
【Here】
If it is in vue, you can also consider using filters to convert
3 methods: 1. Use filter 2. Calculate attributes 3. Methods event Processing event 11-n is relatively simple