首页 > 编程 > JavaScript > 正文

解决vue接口数据赋值给data没有反应的问题

2019-11-19 13:09:06
字体:
来源:转载
供稿:网友

问题:

就是我在接口赋值给了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('请求数据失败')   }) }

以上这篇解决vue接口数据赋值给data没有反应的问题就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持武林网。

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表