vue+ element 小白初次实践踩坑(三)

element 日期选择,要求显示默认当前月份,在绑定数据里的字段

1,首先获取当前月分

getNowTime() {

                let date = new Date();

                let year = date.getFullYear();

                let month = date.getMonth();

                let toMonth = year + '-' + ('00'+ (month + 1)).substr(-2) ;

                this.param.period = toMonth;

            },

在created()里先执行this.getNowTime()

2, <el-table-column prop="period" label="计划周期" width="140">

                    <template slot-scope="scope">

                        <template v-if="edit_index == scope.$index">

                            <el-date-picker

                                  @click.native.stop=""

                                    v-model="param.period"

                                    type="month"

                                    value-format="yyyy-MM"

                                    :default-value="new Date()"

                                    placeholder="选择月">

                            </el-date-picker>

                        </template>

                        <template v-else>

                            {{scope.row.period}}

                        </template>

                    </template>

                </el-table-column>

3,一切都好了,但运行的时候发现没有执行,后来发现在变得时候我清空了数据,所以,需要在编辑的时候再重新执行一遍this.getNowTime()

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容