问题:
就是我在接口赋值给了data的变量,然后组件的效果没有出来(我的是旋转效果)
代码如下:
data() {
return {
slides: []
}
},
mounted() {
this.request()
},
methods: {
request() {
this.$http.post('xxxxxxxxxxxx', {},
(res) => {
if (is. (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. (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('请求数据失败')
})
}

以上这篇解决vue接口数据赋值给data没有反应的问题就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。
继续阅读与本文标签相同的文章
-
最新115道华为、京东、滴滴、美团精选Java面试题整理
2026-05-18栏目: 教程
-
吴伯凡:谁在重新定义我们的城市
2026-05-18栏目: 教程
-
阿里巴巴集团副总裁郭继军:智慧城市建设如何不变成房地产项目
2026-05-18栏目: 教程
-
阿里云RDS for SQL Server购买使用流程
2026-05-18栏目: 教程
-
阿里云智能战略与合作部刘湘雯:阿里关于创新创业服务的思考
2026-05-18栏目: 教程
