vue踩坑记录之数组定义和赋值问题
作者:努力的小聪忙 时间:2024-05-05 09:24:41
问题场景:vue页面初始化展示请求后台返回的数据失败,没有报错
<el-form-item label="有效日期">
<div class="block">
<el-date-picker
v-model="effective_date"
type="daterange"
range-separator="至"
start-placeholder="开始日期"
end-placeholder="结束日期">
</el-date-picker>
</div>
</el-form-item>
data(){
return{
effective_date: []
}
}
methods: {
getContractInfo(){
this.service.hqStore.getContractList(this.$route.query.uid).then((res)=>{
let detail = res.datalist[this.$route.query.index];
this.effective_date[0] = this.stamptimeToDate(detail.valid_date);
this.effective_date[1] = this.stamptimeToDate(detail.invalid_date);
}
}
}
created(){
this.getContractInfo();
setTimeout(()=>{
console.log(this.effective_date);
})
},
输出的this.effective_date
:
页面部分:
发现问题:data定义的数据为[]空数组,没有定义数组长度,而赋值的时候用数组下标赋值
修改代码后如下:
this.effective_date = [this.stamptimeToDate(detail.valid_date),this.stamptimeToDate(detail.invalid_date)];
打印effective_date的值:
页面展示效果:
来源:https://segmentfault.com/a/1190000018583134
标签:vue,数组,赋值
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
利用Python生成Excel炫酷图表
2023-03-09 21:52:00
![](https://img.aspxhome.com/file/2023/8/130998_0s.jpg)
Python网络编程使用select实现socket全双工异步通信功能示例
2023-04-10 21:06:59
python字符串不可变数据类型
2021-04-14 23:07:09
Python高级文件操作之shutil库详解
2022-05-28 10:23:42
![](https://img.aspxhome.com/file/2023/6/110076_0s.png)
Python实现复制图片到指定文件夹并按顺序重新命名
2022-04-25 18:53:06
![](https://img.aspxhome.com/file/2023/4/72194_0s.png)
opencv-python 读取图像并转换颜色空间实例
2022-04-08 04:02:55
交互设计师心得——核心竞争力
2010-01-19 13:45:00
![](https://img.aspxhome.com/file/UploadPic/20101/19/126eb492886g215-16s.jpg)
python 实时调取摄像头的示例代码
2021-10-17 06:07:52
更改Ubuntu默认python版本的两种方法python-> Anaconda
2021-07-30 15:33:28
![](https://img.aspxhome.com/file/2023/7/108137_0s.png)
让ASP组件来保护你的网站,自定义加密方法的使用
2009-11-07 19:27:00
python实现在列表中查找某个元素的下标示例
2023-08-20 07:16:38
![](https://img.aspxhome.com/file/2023/5/131155_0s.png)
MySQL 5数据库连接超时问题
2009-12-29 10:23:00
oracle初始化参数设置
2010-07-31 12:47:00
利用python list完成最简单的DB连接池方法
2022-04-19 18:38:00
![](https://img.aspxhome.com/file/2023/9/95319_0s.jpg)
微信小程序仿今日头条导航栏滚动解析
2024-04-29 13:55:42
[译]2009年海外Web设计风潮(下)
2009-01-23 09:34:00
![](https://img.aspxhome.com/file/UploadPic/20091/23/trend-38-39s.gif)
如何利用python发送邮件
2022-11-09 09:34:31
python分分钟绘制精美地图海报
2021-11-10 11:44:25
![](https://img.aspxhome.com/file/2023/8/133428_0s.png)
SQL Server中链接服务器将替代远程服务器
2009-06-15 11:03:00
Python元组 tuple的概念与基本操作详解【定义、创建、访问、计数、推导式等】
2022-12-08 10:14:45