最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
解决vue接口数据赋值给data没有反应的问题
时间:2022-06-25 15:42:42 编辑:袖梨 来源:一聚教程网
问题:
就是我在接口赋值给了data的变量,然后组件的效果没有出来(我的是旋转效果)
代码如下:
data() {
return {
slides: []
}
},
mounted() {
this.request()
},
methods: {
request() {
this.$http.post('xxxxxxxxxxxx', {},
(res) => {
if (is.object(res)) {
if (res.status === 'succ') {
this.slides = res.data.useddevice_list
console.log(this.slides)
} else {
console.log(res)
}
} else {
this.$toast.show('加载失败')
}
}, (data) => {
this.$toast.show('请求数据失败')
})
}
}
打印出来也是有数据的(但是组件那边没有效果)等功能
解决方法:
因为他是一个[], 一开始加载的时候你去获取数据肯定是undefined, vue官方说了最好提前把所有属性声明好。不管有没有数据也给他一个null
data() {
return {
slides: [null]
}
},
mounted() {
this.request()
},
methods: {
request() {
this.$http.post('xxxxxxxxx', {},
(res) => {
if (is.object(res)) {
if (res.status === 'succ') {
this.slides = res.data.useddevice_list
console.log(this.slides)
} else {
console.log(res)
}
} else {
this.$toast.show('加载失败')
}
}, (data) => {
this.$toast.show('请求数据失败')
})
}
相关文章
- 囧次元动漫app下载安装官方正版-囧次元动漫2025最新版本资源免费下载 12-14
- 知到智慧树官网入口在哪 知到智慧树在线登录网页版 12-14
- 苹果中国官网教育优惠通道-苹果官网以旧换新估价入口 12-14
- 污污漫画入口风险警示-合规访问指南与安全指引 12-13
- 海棠文学城网页版官网入口-2025在线网址直达 12-13
- 土豪漫画官方APP免费下载入口-正版无广告畅读保障 12-13

