vue.js - vue-jalali-moment 过滤器在 v-for 上无法正常工作
问题描述
我想要一个带有 jalai 年份格式的选择,我使用 'vue-jalali-moment' 。
<template>
<div>
<select class="select-year" v-model="year" v-select2>
<option v-for="year in years" :value="year">
@{{ year | moment("jYYYY")}}
</option>
</select>
</div>
</template>
<script>
import select2 from 'select2';
export default {
name: "Profile",
data(){
return {
year: '',
}
},
mounted() {
$('.select-year').select2({
width: '100%',
minimumResultsForSearch: -1,
});
},
computed : {
years () {
const year = new Date().getFullYear()
return Array.from({length: year - 1900}, (value, index) => 1901 + index)
}
}
}
</script>
但我有一个问题,输出是错误的:
<select>
<option value="1901" data-select2-id="15">1348</option>
<option value="1902" data-select2-id="16">1348</option>
<option value="1903" data-select2-id="17">1348</option>
<option value="1904" data-select2-id="18">1348</option>
.
.
.
<option value="2017" data-select2-id="131">1348</option>
<option value="2018" data-select2-id="132">1348</option>
<option alue="2019" data-select2-id="133">1348</option>
</select>
它只为任何公历年生成 1348。
为什么不能正常工作?
解决方案
过滤器需要一个日期,然后您可以创建一个日期数组:
return Array.from({length: year - 1900}, (value, index) => new Date(1901 + index, 1, 1) )
推荐阅读
- elasticsearch - 按文本字段对弹性搜索聚合桶进行排序
- c - 使用 fgets 在同一行上获取两行
- java - 如何解决空对象引用上的“void android.inputmethodservice.KeyboardView$OnKeyboardActionListener.onPress(int)”
- python - 为什么我的回避功能甚至可以工作?语法混乱
- javascript - 循环和渲染元素在 React-native 中不起作用
- python - 从按钮的行和列 tkinter 确定按钮的属性
- android - Calendarview OnselectedDay 更改为时间戳
- swift - 检测返回视图控制器
- google-apps-script - 将电子表格另存为给定文件夹中的 csv 文件
- python - 类生成器定义